Click here to Skip to main content
12,066,448 members (54,311 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0 ASP.NET4
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 22-Feb-12 1:57am
Kiirrii559
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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";
         }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 23 Feb 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100