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();
}
}