我想重设密码我有我的用户名和密码... [英] i want to reset my password i have my user name and password...
本文介绍了我想重设密码我有我的用户名和密码...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想重设密码,我有我的用户名和密码...但是,如果条件满足,在将密码值与用户名进行比较时面临问题,我必须授予该用户更改密码的权限....我想要样品代码说明如何从表中获取密码并与用户名密码或旧密码进行比较
解决方案
1.检查是否在数据库中输入了密码.如果是,则需要在比较之前输入用户输入的密码.
2.对从数据库检索到的值以及从用户获得的值执行一个.trim().这是我的一个应用程序中的示例代码:
字符串用户名= TextBox1.Text.trim(); 字符串密码= EncryptionManager.Encrypt(TextBox2.Text.trim()); 如果(user.ValidateUser(用户名,密码)) { // 用户可以,让他继续前进 } 其他 { Label1.Text = " ; }
最好为此准备一个程序
创建 过程 [dbo].[ResetPassword] @用户名 NVARCHAR ( 50 ) , @ OldPassword NVARCHAR ( 50 ) , @ NewPassword NVARCHAR ( 50 ) AS 开始 设置 没有计数 打开 IF EXISTS ( SELECT * FROM 用户其中用户名= @用户名和 [密码] = @ OldPassword) 开始 更新用户 SET [Password] = @ NewPassword 其中用户名= @用户名 and [密码] = @ OldPassword 返回 1 END ELSE 开始 返回 0 END 设置 没有计数 关闭 END
在.net代码中,执行该过程并检查值
返回1表示重置密码成功
返回0表示旧密码或用户名无效.
希望这会有所帮助,然后接受并投票回答
--Rahul D.
引用此链接
http://www. asp.net/web-forms/tutorials/security/membership/validating-user-credentials-against-the-membership-user-store-cs [ 解决方案
1. check whether the password is encypted in DB or not. if yes u need to encypt the user input password before comparison.
2. perform a .trim() on the value u retrieved from database and also the ones u got from user. here is a sample code from one of my apps:
string username = TextBox1.Text.trim(); string password = EncryptionManager.Encrypt(TextBox2.Text.trim()); if (user.ValidateUser(username, password)) { // user is ok let him pass ahead } else { Label1.Text = "Invalid Username and/or Password"; }
Better to have a procedure for this
CREATE PROCEDURE [dbo].[ResetPassword] @Username NVARCHAR(50) ,@OldPassword NVARCHAR(50) ,@NewPassword NVARCHAR(50) AS BEGIN SET NOCOUNT ON IF EXISTS (SELECT * FROM Users where Username =@Username and [Password]=@OldPassword) BEGIN Update Users SET [Password]=@NewPassword where Username =@Username and [Password]=@OldPassword return 1 END ELSE BEGIN return 0 END SET NOCOUNT OFF END
In .net code execute the procedure and check for the value
return 1 means reset password successful
return 0 means old password or username is invalid.
Hope this helps if yes then accept and vote the answer
--Rahul D.
Refer this link
http://www.asp.net/web-forms/tutorials/security/membership/validating-user-credentials-against-the-membership-user-store-cs[^]
这篇关于我想重设密码我有我的用户名和密码...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文