private void btnSignIn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
try
{
// 檢查用戶身份!
// 獲取登陸IP
string clientIP = Request.ServerVariables["REMOTE_ADDR"];
UserManager um = new UserManager();
// 對密碼進行MD5加密
Byte[] dateToHash = ConvertStringToByteArray(txtUserPassword.Text.Trim());
byte[] hashvalue1 = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(dateToHash);
string userPassword = BitConverter.ToString(hashvalue1).Trim();
// 登陸認證
int i = um.LogonAuthenticate(txtLogonName.Text.Trim(),userPassword,clientIP);
switch(i)
{
case 1:
// 成功登陸
FormsAuthentication.RedirectFromLoginPage(txtLogonName.Text.Trim(),chkAutoSignIn.Checked);
//FormsAuthentication.RedirectFromLoginPage(Server.UrlEncode(txtLogonName.Text.Trim()),chkAutoSignIn.Checked);
//FormsAuthentication.GetRedirectUrl(txtLogonName.Text,false);
//FormsAuthentication.SetAuthCookie(txtLogonName.Text.Trim(),chkAutoSignIn.Checked,@"http://ylh/SSO_Portal");
//string return_url = FormsAuthentication.GetRedirectUrl(txtLogonName.Text,chkAutoSignIn.Checked);
//Response.Write("<script>history.back();</script>");
break;
case 0:
// 帳號凍結
Response.Write("<script>alert('由於您的帳號被管理員凍結,您將無法登陸系統!請與管理員聯繫!');</script>");
break;
default:
// 非法登陸
Response.Write("<script>alert('您不是本系統的合法用戶,此次登陸屬非法登陸!');</script>");
break;
}
}
catch
{
Response.Write("<script>alert('登陸失敗!請稍後再試!');</script>");
}
}
protected void LoginBtn_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
//連接數據庫
string strConn="server=Localhost;uid=sa;pwd=;database=eFrum";
// 連接到eForum數據庫
SqlConnection cn=new SqlConnection(strConn);
// 打開連接
cn.Open();
// 構造SQL語句,該語句在RegUsers表中檢查暱稱和密碼是否正確
String strSQL="select * from regusers where nickname='"+
nickname.Text+"' and password='"+pwd.Text+"'";
// 創建Command對象
SqlCommand cm=new SqlCommand(strSQL,cn);
// 執行ExecuteReader()方法
SqlDataReader dr=cm.ExecuteReader();
if (dr.Read())
{
Message1.Text="";
// 保存當前用戶的暱稱
Session["username"]=dr["nickname"];
Session["upower"]=dr["upower"];
// 進入主畫面
Response.Redirect("index.aspx");
}
else
{
Message1.Text="暱稱/密碼不對,請重新登錄或<a href=adduser.aspx>註冊</a>";
}
// 關閉連接
cn.Close();
}
}
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
this.Cursor=Cursors.Default;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlSelectCommand1.CommandText = "SELECT cbmdh, cbmmc, cpassword FROM getuser WHERE (cbmmc = @cbmmc)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cbmmc", System.Data.SqlDbType.VarChar, 10, "cbmmc"));
this.sqlSelectCommand1.Parameters["@cbmmc"].Value=this.flatTextBox1.Text.ToString();
this.sqlDataAdapter1.Fill(this.dataSet11);
if(this.flatTextBox1.Text!="")
{
if(this.dataSet11.Tables["getuser"].Rows.Count>0)
{
try
{
this.dataSet11.Tables["getuser"].Rows.Clear();
this.sqlDataAdapter2.SelectCommand = this.sqlSelectCommand2;
this.sqlSelectCommand2.CommandText = "SELECT cbmdh, cbmmc, cpassword FROM getuser WHERE (cbmmc = @cbmmc) AND (cpassword = @cpassword)";
this.sqlSelectCommand2.Connection = this.sqlConnection1;
this.sqlSelectCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cbmmc", System.Data.SqlDbType.VarChar, 10, "cbmmc"));
this.sqlSelectCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cpassword", System.Data.SqlDbType.VarChar, 10, "cpassword"));
this.sqlSelectCommand2.Parameters["@cbmmc"].Value=this.flatTextBox1.Text.ToString();
this.sqlSelectCommand2.Parameters["@cpassword"].Value=this.flatTextBox2.Text.ToString();
this.sqlDataAdapter2.Fill(this.dataSet11);
if(this.dataSet11.Tables["getuser"].Rows.Count==1)
{
Mainform mf=new Mainform();
mf.Show();
this.Visible=false;
this.Dispose(false);
}
else
{
MessageBox.Show("密碼錯誤,請重新填寫!");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("該用戶不存在,請重新登錄!");
this.flatTextBox3.Focus();
this.flatTextBox3.Cursor=Cursors.Default;
}
}
else
{
MessageBox.Show("用戶名不能爲空!");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
this.dataSet11.Dispose();
this.sqlDataAdapter1.Dispose();
this.sqlDataAdapter2.Dispose();
}
}