本文将给出通过C#编程来实现 忘记密码 功能的方法和代码大家可以参照本文的思路自己写出这个功能代码……
以下是引用片段intresult=userGetBackPassword(LoginNameTextTrim()
QuestionTextTrim()
AnswerTextTrim()EmailText);
if(result==)
{
MessageText=您的密码已发送请到邮箱查收;
//userChangePassword(
}
else
{
MessageText=您的输入信息有误!;
}
publicintGetBackPassword(stringuserNamestringquestionstringanswer
stringemail)
{
objectm_DBNull=ConvertDBNull;
//获得新的随机密码
stringnewPassword=MakePassword();
//定义存储过程参数
SqlParameter[]para={
newSqlParameter(@userNameuserName)
newSqlParameter(@questionquestion)
newSqlParameter(@answeranswer)
newSqlParameter(@newPasswordnewPassword)
newSqlParameter(@resultSqlDbTypeIntParameterDirectionOutput
trueDataRowVersionDefaultm_DBNull)
};
//执行存储过程
try
{
DALSQLHelperExecuteNonQuery(DALSQLHelperCONN_STRING
CommandTypeStoredProcedure
GetBackPwdpara);
}
catch
{
thrownewException(邮件无法发送!);
}
//获得输出参数的值
intresult=ConvertToInt(para[]Value);
//如果密码保护资料填写正确
if(result==)
{
//从nfig获取发信人地址邮件标题邮件用户名和密码以及SmtpServer
stringsender=SystemConfigurationConfigurationSettings
AppSettings[mainSender];
stringtitle=SystemConfigurationConfigurationSettings
AppSettings[mailTitle];
stringmailUser=SystemConfigurationConfigurationSettings
AppSettings[mailUser];
stringmailPwd=SystemConfigurationConfigurationSettings
AppSettings[mailPwd];
stringsmtpServer=SystemConfigurationConfigurationSettings
AppSettings[mailSmtpServer];
//发信
try
{
MailCDOsendmail(senderemailtitle
您在eshop的密码已找回新密码为+newPassword
mailUsermailPwdsmtpServer);
}
catch(Exceptionex)
{
thrownewException(exMessage);
}
}
returnresult;
}
//随机生成密码
privatestaticstringMakePassword(intpwdLength)
{
//声明要返回的字符串
stringtmpstr=;
//密码中包含的字符数组
stringpwdchars=abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ;
//数组索引随机数
intiRandNum;
//随机数生成器
Randomrnd=newRandom();
for(inti=;i<pwdLength;i++)
{
//Random类的Next方法生成一个指定范围的随机数
iRandNum=rndNext(pwdcharsLength);
//tmpstr随机添加一个字符
tmpstr+=pwdchars[iRandNum];
}
returntmpstr;
}
ALTERPROCEDUREGetBackPwd
@questionnvarchar()
@answernvarchar()
@userNamenvarchar()
@newPasswordnvarchar()
@resultintoutput
AS
ifexists(SELECT*FROMUSERINFOWHEREUSERNAME=@USERNAMEAND
QUESTION=@QUESTION
ANDANSWER=@ANSWER)
BEGIN
SET@RESULT=
UPDATEUSERINFO
SETUSERPWD=@newPassword
WHEREuserName=@userName
END
ELSE
BEGIN
SET@RESULT=
END
GO
SETQUOTED_IDENTIFIEROFF
GO
SETANSI_NULLSON
GO
<addkey=mailUservalue=/>
<addkey=mailPwdvalue=/>
<addkey=mailSmtpServervalue=/>
<addkey=mailSendervalue=/>
<addkey=mailTitlevalue=/>