Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to reset my password i have my user name and password...but facing problem in comparing values of password to username if condition satisfy i have to give permission to that user to change password.... i want sample code how to fetch password from table and compare it wit username's password or old password
Posted

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:

C#
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";
         }
 
Share this answer
 
Better to have a procedure for this

SQL
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900