本文將給出通過C#編程來實現 忘記密碼 功能的方法和代碼
以下是引用片段
int result = user
Question
Answer
if (result ==
{
Message
//user
}
else
{
Message
}
public int GetBackPassword(string userName
string email)
{
object m_DBNull = Convert
//獲得新的隨機密碼
string newPassword = MakePassword(
//定義存儲過程參數
SqlParameter[] para = {
new SqlParameter(
new SqlParameter(
new SqlParameter(
new SqlParameter(
new SqlParameter(
true
};
//執行存儲過程
try
{
DAL
CommandType
}
catch
{
throw new Exception(
}
//獲得輸出參數的值
int result = Convert
//如果密碼保護資料填寫正確
if (result ==
{
//從nfig獲取發信人地址
string sender = System
AppSettings[
string title = System
AppSettings[
string mailUser = System
AppSettings[
string mailPwd = System
AppSettings[
string smtpServer = System
AppSettings[
//發信
try
{
Mail
}
catch(Exception ex)
{
throw new Exception(ex
}
}
return result;
}
//隨機生成密碼
private static string MakePassword(int pwdLength)
{
//聲明要返回的字符串
string tmpstr =
//密碼中包含的字符數組
string pwdchars=
ABCDEFGHIJKLMNOPQRSTUVWXYZ
//數組索引隨機數
int iRandNum;
//隨機數生成器
Random rnd = new Random();
for(int i=
{
//Random類的Next方法生成一個指定范圍的隨機數
iRandNum = rnd
//tmpstr隨機添加一個字符
tmpstr += pwdchars[iRandNum];
}
return tmpstr;
}
ALTER PROCEDURE GetBackPwd
@question nvarchar(
@answer nvarchar(
@userName nvarchar(
@newPassword nvarchar(
@result int output
AS
if exists (SELECT * FROM USERINFO WHERE USERNAME=@USERNAME AND
QUESTION=@QUESTION
AND ANSWER=@ANSWER)
BEGIN
SET @RESULT =
UPDATE USERINFO
SET USERPWD = @newPassword
WHERE userName = @userName
END
ELSE
BEGIN
SET @RESULT =
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
<add key=
<add key=
<add key=
<add key=
<add key=
From:http://tw.wingwit.com/Article/program/ASP/201311/21715.html