Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I am new to asp.net and trying to create one application where at the time of
resetting password user should not able to use his 5 old passwords.
but I am not able to understand how to maintain the password history for each user in database.
Plzzz help me.

What I have tried:

this is the table I have for registration of user

ID int
First_Name varchar2(50)
Last_Name varchar2(50)
password varchar2(50)
email varchar2(50)

I have done the registration and login page with this table.
SO here what changes required for maintain the history of password for each user.
Posted
Updated 15-Mar-17 2:16am
Comments
Karthik_Mahalingam 14-Feb-17 5:54am    
check this
http://stackoverflow.com/a/9493800/1147428

1 solution

Lots of ways of doing this really. You're probably going to need a new table though

User (ID, First_Name, Last_Name, email)

Passwords (ID, UserID, Password, Active (bit))

SQL
User
----
1 | John | Doe | me@here.com

Password
--------

1 | 1 | hello | 0
2 | 1 | world | 1


So User 1, Joe, has a current password of "world" and a previous password of "hello". You'll probably want a date field on that Password too which shows when the password was created. To get the current password you just JOIN User with Password

SELECT * FROM [User] u JOIN [Password] p on p.UserID = u.ID and p.Active = 1

That method would need an index on the UserID column of the Password table. The alternative would be like this

User (ID, First_Name, Last_Name, email, PasswordID)

Passwords (ID, UserID, Password)

SQL
User
----
1 | John | Doe | me@here.com | 2

Password
--------

1 | 1 | hello
2 | 1 | world


Then to get the password you'd JOIN the Password table on the PasswordID on User. With either method you'd then simply check old passwords when creating new ones, and if their history exceeds 5 delete any beyond the fifth.

Also I hope you are encrypting your passwords and not storing them in plain text.
 
Share this answer
 
Comments
prakashraj2890 15-Feb-17 1:24am    
Thanks for your reply.. :)
But I am facing one problem here


User (ID, First_Name, Last_Name, email)

Passwords (ID, UserID, Password, Active (bit))

Here in User table 'ID' column is identity column
So at the time of inserting data in Passwords table not able to get the 'UserId' column value in storeprocedure
F-ES Sitecore 15-Feb-17 4:05am    
When you are changing a password you'll know the userid that you are creating it for so you'd simply inject it into the table. When you create a user for the first time you need to do two inserts. First you insert the user and get the ID of that user, then insert into the password table.
prakashraj2890 15-Feb-17 5:01am    
This I have done..
here I am checking entered email is already used for registration if yes then not allowing to get register(sorry for bad English)
I have used '@@IDENTITY' this function. please suggest me where it is good to use this function or have other better alternative .
Thanks.



create proc spRegistration
@fname nvarchar(20),
@lname nvarchar(20),
@password nvarchar(20),
@email nvarchar(20)
as
Begin
declare @uid int
declare @Count int
declare @ReturnCode int

select @Count = COUNT(email)
from userinfo where email=@email
if @Count> 0
Begin
set @ReturnCode=-1
end
else
begin set @ReturnCode=1
Insert into userinformation values
(@fname,@lname,@email)

set @uid=@@IDENTITY
insert into passhistory (userId,password,Active ) values(@uid,@password,1)
end
select @ReturnCode as ReturnValue
End
F-ES Sitecore 15-Feb-17 5:27am    
You should use SCOPE_IDENTITY instead of @@IDENTITY

set @uid=SCOPE_IDENTITY()
prakashraj2890 15-Feb-17 6:05am    
ok thanks a lot

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