//获取所有用户的用户名 public DataSet GetAllUsername(sql_user user) { SqlParameter[] parms = { }; return(data.RunProcReturn("select username from users", parms, "users")); }
protected void reset_button_Click(object sender, EventArgs e) { if (IsPasswdSame(password.Text, password_check.Text)) { sql_user myuser = new sql_user(); myuser.Email = Request.QueryString["email"]; myuser.ResetCode = Request.QueryString["resetcode"]; string db_password = password.Text; string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(db_password, "MD5"); myuser.PassWord = pass; if (myuser.UpdateUserPassword(myuser) == 0) { myuser.EmailResetCodeDelete(myuser);//从resetcode表中删除记录 WebMessageBox.Show("密码重置成功,请使用新密码登录", "../index.aspx"); } } else { WebMessageBox.Show("两次密码输入不一致,请重新输入", "forget_password_FindByEmail_ResetPassword.aspx"); //RegisterStartupScript("", "<script>alert('两次密码输入不一致,请重新输入') </script>"); //Response.Redirect("forget_password_FindByEmail_ResetPassword.aspx"); } }
//通过邮箱更新密码 public int UpdateUserPassword(sql_user user) { SqlParameter[] parms = { data.MakeInParam("@Email", SqlDbType.VarChar, 50, user.email), data.MakeInParam("@PassWord", SqlDbType.VarChar, 50, user.password), }; return(data.RunProc("update users set password=@PassWord where email=@Email", parms)); }
//删除重置码 public int EmailResetCodeDelete(sql_user user) { SqlParameter[] parms = { data.MakeInParam("@Email", SqlDbType.VarChar, 50, user.email), data.MakeInParam("@ResetCode", SqlDbType.VarChar, 50, user.resetcode), }; return(data.RunProc("delete from resetcode where email=@Email and resetcode=@ResetCode", parms)); }
//更新用户激活状态 public int UpdateUserStatus(sql_user user) { SqlParameter[] parms = { data.MakeInParam("@UserName", SqlDbType.VarChar, 50, user.username), data.MakeInParam("@Status", SqlDbType.TinyInt, 1, user.status), }; return(data.RunProc("update users set status=1 where username=@username", parms)); }
//注册用户重置码 public int InsertUserResetCode(sql_user user) { SqlParameter[] parms = { data.MakeInParam("@UserName", SqlDbType.VarChar, 50, user.username), data.MakeInParam("@ResetCode", SqlDbType.VarChar, 50, user.resetcode), }; return(data.RunProc("insert into resetcode(username,resetcode) values(@UserName,@ResetCode) ", parms)); }
public void SetMatchUsernameAndMatchUserCountAndMatchUserScore(sql_user matchuser) { match_user_count = matchuser.GetAllUsername(matchuser).Tables[0].Rows.Count; match_username = new string[match_user_count]; match_score = new int[match_user_count]; for (int i = 0; i < match_user_count; i++) { match_username[i] = matchuser.GetAllUsername(matchuser).Tables[0].Rows[i]["username"].ToString(); } }
//验证重置码 public DataSet EmailResetCodeSelect(sql_user user) { SqlParameter[] parms = { data.MakeInParam("@Email", SqlDbType.VarChar, 50, user.email), data.MakeInParam("@ResetCode", SqlDbType.VarChar, 50, user.resetcode), }; return(data.RunProcReturn("SELECT * FROM resetcode WHERE email = @Email and resetcode=@ResetCode", parms, "user")); }
protected void Page_Load(object sender, EventArgs e) { sql_user myuser = new sql_user(); myuser.Email = Request.QueryString["email"]; myuser.ResetCode = Request.QueryString["resetcode"]; if (myuser.EmailResetCodeSelect(myuser).Tables[0].Rows.Count <= 0) { WebMessageBox.Show("非法验证码!请从邮箱所发链接进入", "../index.aspx"); } }
protected bool IsNotExistEmail(string email) { bool IsNotExist = true; sql_user myuser = new sql_user(); myuser.Email = email; if (myuser.IsEmailExist(myuser).Tables[0].Rows.Count > 0) { IsNotExist = false; } //con.Close(); return(IsNotExist); }
//用于判断邮箱是否存在 public DataSet IsEmailExist(sql_user user) { SqlParameter[] parms = { //data.MakeInParam("@UserName",SqlDbType.VarChar,50,user.username), //data.MakeInParam("@PassWord",SqlDbType.VarChar,50,user.password), data.MakeInParam("@Email", SqlDbType.VarChar, 50, user.email), //data.MakeInParam("@UserName",SqlDbType.VarChar,50,user.phone), //data.MakeInParam("@UserName",SqlDbType.Int,50,user.status), //data.MakeInParam("@UserName",SqlDbType.Int,50,user.grank), // data.MakeInParam("@UserName",SqlDbType.VarChar,50,user.sex), }; return(data.RunProcReturn("select * from users where email=@Email", parms, "users")); }
//由邮箱登录 public DataSet LoginByEmail(sql_user user) { SqlParameter[] parms = { //data.MakeInParam("@UserName",SqlDbType.VarChar,50,user.username), data.MakeInParam("@Email", SqlDbType.VarChar, 50, user.email), data.MakeInParam("@PassWord", SqlDbType.VarChar, 50, user.password), //data.MakeInParam("@UserName",SqlDbType.VarChar,50,user.phone), //data.MakeInParam("@UserName",SqlDbType.Int,50,user.status), //data.MakeInParam("@UserName",SqlDbType.Int,50,user.grank), // data.MakeInParam("@UserName",SqlDbType.VarChar,50,user.sex), }; //返回结果集的方式,使用data.Tables[0].Rows.Count取得行数判断是否登录成功 return(data.RunProcReturn("select * from users where email=@Email and password=@PassWord", parms, "users")); }
//用户邮箱注册 public int RegisterByPhone(sql_user user) { SqlParameter[] parms = { data.MakeInParam("@UserName", SqlDbType.VarChar, 50, user.username), data.MakeInParam("@PassWord", SqlDbType.VarChar, 50, user.password), data.MakeInParam("@Email", SqlDbType.VarChar, 50, user.email), data.MakeInParam("@Phone", SqlDbType.VarChar, 50, user.phone), //data.MakeInParam("@UserName",SqlDbType.Int,50,user.status), //data.MakeInParam("@UserName",SqlDbType.Int,50,user.grank), // data.MakeInParam("@UserName",SqlDbType.VarChar,50,user.sex), }; //返回结果集的方式,使用data.Tables[0].Rows.Count取得行数判断是否登录成功 return(data.RunProc("insert into users(username,password,email,phone) values(@UserName,@PassWord,0,@Phone) ", parms)); }
public bool IsStatusValid(sql_user user) { SqlParameter[] parms = { data.MakeInParam("@UserName", SqlDbType.VarChar, 50, user.username), // data.MakeInParam("@Status",SqlDbType.Int,50,user.status), }; if (data.RunProcReturn("select * from users where username=@Username", parms, "users").Tables[0].Rows[0]["status"].ToString() == "1") { return(true); } else { return(false); } }
protected void Page_Load(object sender, EventArgs e) { //用于ajax实时检测用户名是否存在 if (Request.QueryString["check_username"] != null) { string username_to_check = Request.QueryString["check_username"].ToString(); sql_user myuser = new sql_user(); myuser.UserName = username_to_check; if (myuser.IsUserExist(myuser).Tables[0].Rows.Count > 0) { Response.Write("此用户已存在"); } else { Response.Write("此用户名可使用"); } } }
protected bool IsExistUser(string username) { bool IsExist = false; sql_user myuser = new sql_user(); myuser.UserName = username; /* * string sqlCheckUsername = "******"; * SqlConnection con = new SqlConnection("server=.;database=MarriageAndLove;uid=sa;pwd=19940919;"); * con.Open(); * SqlCommand comCheckUsername = new SqlCommand(sqlCheckUsername, con); * comCheckUsername.Parameters.Add(new SqlParameter("username", SqlDbType.VarChar, 50)); * comCheckUsername.Parameters["username"].Value = username; */ //if (Convert.ToInt32(comCheckUsername.ExecuteScalar()) > 0) if (myuser.IsUserExist(myuser).Tables[0].Rows.Count > 0) { IsExist = true; } //con.Close(); return(IsExist); }
protected void findpassword_button_Click(object sender, EventArgs e) { if (IsNotExistEmail(email.Text)) { WebMessageBox.Show("该邮箱不存在,请确认填写的邮箱", "forget_password_FindByEmail.aspx"); //RegisterStartupScript("", "<script>alert('该邮箱不存在,请确认填写的邮箱')</script>"); //Response.Redirect("forget_password_FindByEmail.aspx"); } else { string db_email = email.Text; //创建数据库连接 /*SqlConnection con = new SqlConnection("server=.;database=MarriageAndLove;uid=sa;pwd=conan;"); * //打开数据库连接 * con.Open(); * //使用MD5加密将用户输入的密码加密 * string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(password.Text, "MD5"); * //创建SQL语句,该语句用来查询用户输入的用户名和密码是否正确 * //此处phone不允许插入空值,由于手机注册的原因,故暂时用0替代 * string sqlSel = "insert into users(username,password,email,phone) values(@username,@password,@email,0)"; * //创建SqlCommand对象 * SqlCommand com = new SqlCommand(sqlSel, con); * //使用Parameters的add方法添加参数类型 * com.Parameters.Add(new SqlParameter("email", SqlDbType.VarChar, 32)); * //设置Parameters的参数值 * com.Parameters["email"].Value = db_email; * com.Parameters.Add(new SqlParameter("password", SqlDbType.VarChar, 32)); * com.Parameters["password"].Value = pass; * com.Parameters.Add(new SqlParameter("username", SqlDbType.VarChar, 32)); * com.Parameters["username"].Value = db_username; * */ //string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(password.Text, "MD5"); sql_user myuser = new sql_user(); myuser.Email = db_email; Session["email"] = db_email; string temp = "0"; temp = rnumber(); myuser.ResetCode = temp; /*string sqladd = "insert into resetcode(email,resetcode) values(@email,@resetcode)"; * SqlConnection con = new SqlConnection("Server=localhost;DataBase=MarriageAndLove;User=sa;Password=conan"); * con.Open(); * SqlCommand comm = new SqlCommand(sqladd, con); * * comm.Parameters.Add(new SqlParameter("email", SqlDbType.VarChar, 32)); * comm.Parameters["email"].Value = db_email; * comm.Parameters.Add(new SqlParameter("resetcode", SqlDbType.VarChar, 32)); * comm.Parameters["resetcode"].Value = temp; * comm.ExecuteNonQuery(); */ if (myuser.InsertUserResetCode(myuser) == 0) { sendmail(db_email, temp); WebMessageBox.Show("重置密码的邮件已发送至信箱", "forget_password_FindByEmail.aspx"); //RegisterStartupScript("", "<script>alert('注册成功,激活邮件已发送至信箱')</script>"); //加入user表status属性后判断状态需判断status,激活邮件部分以后再写 //Response.Redirect("../index.aspx"); //string db_password = pasword.Text; } } }
protected void register_button_Click(object sender, EventArgs e) { if (IsExistUser(username.Text)) { RegisterStartupScript("", "<script>alert('用户名已存在,请使用其他用户名注册')</script>"); Response.Redirect("register_by_email.aspx"); } else { if (IsPasswdSame(password.Text, password_check.Text)) { string db_email = email.Text; string db_username = username.Text; string db_password = password.Text; //创建数据库连接 /*SqlConnection con = new SqlConnection("server=.;database=MarriageAndLove;uid=sa;pwd=conan;"); * //打开数据库连接 * con.Open(); * //使用MD5加密将用户输入的密码加密 * string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(password.Text, "MD5"); * //创建SQL语句,该语句用来查询用户输入的用户名和密码是否正确 * //此处phone不允许插入空值,由于手机注册的原因,故暂时用0替代 * string sqlSel = "insert into users(username,password,email,phone) values(@username,@password,@email,0)"; * //创建SqlCommand对象 * SqlCommand com = new SqlCommand(sqlSel, con); * //使用Parameters的add方法添加参数类型 * com.Parameters.Add(new SqlParameter("email", SqlDbType.VarChar, 32)); * //设置Parameters的参数值 * com.Parameters["email"].Value = db_email; * com.Parameters.Add(new SqlParameter("password", SqlDbType.VarChar, 32)); * com.Parameters["password"].Value = pass; * com.Parameters.Add(new SqlParameter("username", SqlDbType.VarChar, 32)); * com.Parameters["username"].Value = db_username; * */ string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(db_password, "MD5"); sql_user myuser = new sql_user(); myuser.Email = db_email; myuser.UserName = db_username; myuser.PassWord = pass; if (myuser.RegisterByEmail(myuser) == 0) { Session["username"] = db_username; string temp = "0"; temp = rnumber(); myuser.ActiveCode = temp; /*string sqladd = "insert into activecode(username,activecode) values(@username,@activecode)"; * SqlConnection con = new SqlConnection("Server=localhost;DataBase=MarriageAndLove;User=sa;Password=conan"); * con.Open(); * SqlCommand comm = new SqlCommand(sqladd, con); * * comm.Parameters.Add(new SqlParameter("username", SqlDbType.VarChar, 32)); * comm.Parameters["username"].Value = db_username; * comm.Parameters.Add(new SqlParameter("activecode", SqlDbType.VarChar, 32)); * comm.Parameters["activecode"].Value = temp; * comm.ExecuteNonQuery(); */ if (myuser.InsertUserActiveCode(myuser) == 0) { sendmail(db_email, db_username, temp); WebMessageBox.Show("注册成功,激活邮件已发送至信箱", "../index.aspx"); //RegisterStartupScript("", "<script>alert('注册成功,激活邮件已发送至信箱')</script>"); //加入user表status属性后判断状态需判断status,激活邮件部分以后再写 //Response.Redirect("../index.aspx"); } } else { WebMessageBox.Show("邮箱注册失败,请重新注册", "register_by_email.aspx"); //Response.Redirect("register_by_email.aspx"); } } else { WebMessageBox.Show("两次密码输入不一致,请重新输入", "register_by_email.aspx"); //RegisterStartupScript("", "<script>alert('两次密码输入不一致,请重新输入') </script>"); //Response.Redirect("register_by_email.aspx"); } //string db_password = pasword.Text; } }
protected void register_button_Click(object sender, EventArgs e) { if (IsExistUser(username.Text)) { RegisterStartupScript("", "<script>alert('用户名已存在,请使用其他用户名注册')</script>"); Response.Redirect("register_by_phone.aspx"); } else { if (IsPasswdSame(password.Text, password_check.Text)) { string db_phone = phone.Text; string db_username = username.Text; string db_password = password.Text; //创建数据库连接 //SqlConnection con = new SqlConnection("server=.;database=MarriageAndLove;uid=sa;pwd=19940919;"); //打开数据库连接 //con.Open(); sql_user myuser = new sql_user(); //使用MD5加密将用户输入的密码加密 string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(db_password, "MD5"); myuser.Phone = db_phone; myuser.UserName = db_username; myuser.PassWord = pass; //创建SQL语句,该语句用来查询用户输入的用户名和密码是否正确 //此处phone不允许插入空值,由于手机注册的原因,故暂时用0替代 //string sqlSel = "insert into users(username,password,email,phone) values(@username,@password,@email,0)"; //创建SqlCommand对象 //SqlCommand com = new SqlCommand(sqlSel, con); //使用Parameters的add方法添加参数类型 /*com.Parameters.Add(new SqlParameter("email", SqlDbType.VarChar, 32)); * //设置Parameters的参数值 * com.Parameters["email"].Value = db_email; * com.Parameters.Add(new SqlParameter("password", SqlDbType.VarChar, 32)); * com.Parameters["password"].Value = pass; * com.Parameters.Add(new SqlParameter("username", SqlDbType.VarChar, 32)); * com.Parameters["username"].Value = db_username; */ if (myuser.RegisterByPhone(myuser) == 0) { Session["username"] = db_username; RegisterStartupScript("", "<script>alert('注册成功,激活邮件已发送至信箱')</script>"); //加入user表status属性后判断状态需判断status,激活邮件部分以后再写 Response.Redirect("../index.aspx"); } else { RegisterStartupScript("", "<script>alert('注册失败,请重新注册')</script>"); Response.Redirect("register_by_email.aspx"); } } else { RegisterStartupScript("", "<script>alert('两次密码输入不一致,请重新输入') </script>"); Response.Redirect("register_by_email.aspx"); } //string db_password = pasword.Text; } }