扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
以下是引用片段: int result = user.GetBackPassword(LoginName.Text.Trim(), Question.Text.Trim(), Answer.Text.Trim(), Email.Text); if (result == 1) { Message.Text = "您的密码已发送,请到 //user.ChangePassword( } else { Message.Text = "您的输入 } public int GetBackPassword(string userName, string question, string answer, string email) { object m_DBNull = Convert.DBNull; //获得新的随机密码 string newPassword = MakePassword(6); //定义存储过程参数 SqlParameter[] para = { new SqlParameter("@userName", userName), new SqlParameter("@question", question), new SqlParameter("@answer", answer), new SqlParameter("@newPassword", newPassword), new SqlParameter("@result", SqlDbType.Int, 8, ParameterDirection.Output, true, 0, 0, "", DataRowVersion.Default, m_DBNull) }; //执行存储过程 try { DAL.SQLHelper.ExecuteNonQuery(DAL.SQLHelper.CONN_STRING, CommandType.StoredProcedure, "GetBackPwd", para); } catch { throw new Exception("邮件无法发送!"); } //获得输出参数的值 int result = Convert.ToInt32(para[4].Value); //如果密码保护资料填写正确 if (result == 1) { //从Web.config获取发信人 string sender = System.Configuration.ConfigurationSettings.AppSettings["mainSender"]; string title = System.Configuration.ConfigurationSettings.AppSettings["mailTitle"]; string mailUser = System.Configuration.ConfigurationSettings.AppSettings["mailUser"]; string mailPwd = System.Configuration.ConfigurationSettings.AppSettings["mailPwd"]; string smtpServer = System.Configuration.ConfigurationSettings.AppSettings["mailSmtpServer"]; //发信 try { Mail.CDOsendmail(sender, email, title, "您在eshop的密码已找回,新密码为"+newPassword , mailUser, mailPwd, smtpServer); } catch(Exception ex) { throw new Exception(ex.Message); } } return result; } //随机生成密码 private static string MakePassword(int pwdLength) { //声明要返回的字符串 string tmpstr = ""; //密码中包含的字符数组 string pwdchars="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //数组索引随机数 int iRandNum; //随机数生成器 Random rnd = new Random(); for(int i=0;i<pwdLength;i++) { //Random类的Next方法生成一个指定范围的随机数 iRandNum = rnd.Next(pwdchars.Length); //tmpstr随机添加一个字符 tmpstr += pwdchars[iRandNum]; } return tmpstr; } ALTER PROCEDURE GetBackPwd @question nvarchar(50), @answer nvarchar(50), @userName nvarchar(50), @newPassword nvarchar(50), @result int output AS if exists (SELECT * FROM USERINFO WHERE USERNAME=@USERNAME AND QUESTION=@QUESTION AND ANSWER=@ANSWER) BEGIN SET @RESULT = 1 UPDATE USERINFO SET USERPWD = @newPassword WHERE userName = @userName END ELSE BEGIN SET @RESULT = -1 END GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO <add key="mailUser" value="" /> <add key="mailPwd" value="" /> <add key="mailSmtpServer" value="" /> <add key="mailSender" value="" /> <add key="mailTitle" value="" /> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者