DVerde
DVerde

Reputation: 27

Password change every 90 days in MVC and SQL Server

I want a method to ask the user to change his password after having it for 90 days.

I have something like this

ALTER PROCEDURE [dbo].[spRecoverPassword]
(
   @sUsername varchar(50),
   @sPassword varchar(100),
   @sPasswordSalt varchar (128)
)
AS
BEGIN
    SET NOCOUNT ON;

    if (exists (select 1
                from USER
                where Username = @sUsername))
    begin
        update USER
        set Password_Salt = @sPasswordSalt,
            Password = @sPassword,
        where Username = @sUsername;

        select 1;
    end
    else 
    begin
        select -1;
    end
END    

Then I have a method to call this stored procedure, from ASP.NET MVC. And somehow I would like to check the date that the password was last changed and do so that if that date is 90 days higher than today it will redirect it to the recover pass again. How should I do this?

Thanks

Upvotes: 0

Views: 1149

Answers (2)

meda
meda

Reputation: 45490

Very easy:

  1. add a date field in USER table for example last_changed.
  2. update last_changed with now() in the query
  3. check days difference DATEDIFF(now(),last_changed)>90

Upvotes: 2

Ankit Arora
Ankit Arora

Reputation: 111

Add a new column in users Table to save last modified date of password. on Get method calculate the difference between Last modified date of password and today's date. and do what you want to do.

Upvotes: 2

Related Questions