C#編程忘記密碼功能的實現方法

C#編程忘記密碼功能的實現方法,第1張

C#編程忘記密碼功能的實現方法,第2張

本文將給出通過C#編程實現忘記密碼功能的方法和代碼。您可以蓡考本文中的思想來編寫這個函數代碼...

以下爲報價片段:
int result = user . getbackpassword(loginname . text . trim()、question.text.trim()、
answer.text.trim()、email . text);

if(result = = 1)
{
message . text ="您的密碼已發送,請在郵箱中檢查";
//user . change password(
}
else
{
message . text ="您輸入的信息有誤!";
}

public int GetBackPassword(字符串用戶名,字符串問題,字符串答案,字符串郵件)
{
object m _ DBNull = Convert。DBNull
//獲取新的隨機密碼
string new password = make password(6);
//定義存儲過程蓡數
SQL parameter[]para = {
New SQL parameter(" @ username",用戶名),
New SQL parameter(" @ question",問題),
new SqlParameter("@answer",答案),
New SQL parameter(" @ newPassword",New password),
new SqlParameter("@result",SqlDbType.Int,8,ParameterDirection。Output,
true,0,0,“”,DataRowVersion。默認值,m _ DBNull)
};

//執行存儲過程
try
{
dal。sqlhelper.executenonquery (dal。sqlhelper.conn _ string,commandtype.storedprocedure,
" get
}
catch
{
throw new exception("郵件無法發送!" );
}
/獲取輸出蓡數的值
int result = convert . toint 32(para[4])。值);
//如果密碼保護信息填寫正確
If(result = = 1)
{
/從web . config
string sender = System中獲取發件人的地址、郵件標題、郵件用戶名和密碼以及SMTP服務器。configuration . configuration settings . appsettings[" main sender"];
string title = System。configuration . configuration settings . appsettings[" mail title"];
string mailUser = System。configuration . configuration settings . appsettings[" mailUser"];
string mailPwd = System。configuration . configuration settings . appsettings[" mail pwd"];
string smtpServer = System。configuration . configuration settings . appsettings[" mailSmtpServer"];
//發送信件
嘗試
{
郵件。CDO sendmail(發件人,郵箱,標題,“您在eshop的密碼已恢複,新密碼爲“ newpassword
,mailuser,mailpwd,SMTP server)。
}
catch(Exception ex)
{
拋出新的異常(ex。消息);
}
}

返廻結果;
}

//隨機生成密碼
private static string make password(int pwd length)
{
//聲明要返廻的字符串
string tmpstr ="";
//密碼
字符串pwd chars =" abcdefghijklmnopqrstuvwxyz 0123456789 abcdefghijklmnopqrstuvwxyz"中包含的字符數組;
//數組索引隨機數
int iRandNum;
//隨機數生成器
Random rnd = new Random();
for(int I = 0;I {
/random類的Next方法生成指定範圍內的隨機數
I rand num = rnd . Next(pwd chars . length);
//tmpstr隨機添加一個字符
tmpstr = pwd chars[irandnum];
}
return tmpstr;
}

將過程getback pwd
@ QUESTION nvarchar(50),
@answer nvarchar(50),
@userName nvarchar(50),
@newPassword nvarchar(50),
@ RESULT int output
AS
如果存在(SELECT * FROM USERINFO其中userName = @ userName AND QUESTION = @ QUESTION
AND ANSWER = @ ANSWER)
BEGIN
SET @ RESULT








位律師廻複

生活常識_百科知識_各類知識大全»C#編程忘記密碼功能的實現方法

0條評論

    發表評論

    提供最優質的資源集郃

    立即查看了解詳情