0

I am in the process of making a ASP.NET C# Website and i need to output the last time the user has changed their password into a label.

Do i need to create a seperate tabel in my database for this? Or is there a function i can just call from somewhere?

I did do some research and i believe i have to use:

public virtual DateTime LastPasswordChangedDate { get; }

But i cannot find out how to implement this into my website as all examples with this that i could find simply use it to create a system to force users to change their password after a set amount of time and not to write the current value to a String.

Any help will be much appreciated.

Problem solved,

MembershipUser u = Membership.GetUser();
PWChangeDateLabel.Text = u.LastPasswordChangedDate.ToString("d/m/yyyy"); 
Cinedine
  • 23
  • 2
  • 18
  • 1
    How are you handling authentication? Are you using a membership provider database – theedam Apr 09 '14 at 13:39
  • I am not very experienced with databases i hope this answers your question, For user unput i used the Miscrosoft V4.0.0.0 Login Tools. It is connected to a SQL Server 2008 Database – Cinedine Apr 09 '14 at 13:43
  • Are you making a page that displays all of the users and their last password change datetime? Or is this for an individual user profile? Not that it really matters, basically either whatever authentication classes you are using will have a property to say "LastPassWordChanged" or you'll have to write a query to select this information out of the database – theedam Apr 09 '14 at 13:48
  • When a user log's in to my website they get a page where they can see and edit their own user settings including their password. I want to display the last time they changed their password there. – Cinedine Apr 09 '14 at 13:56
  • If you're not using SqlMembershipProvider you should look at using it as it will offer you what you want and has lots of inbuilt controls and functions http://www.asp.net/web-forms/tutorials/security/membership/creating-the-membership-schema-in-sql-server-cs – theedam Apr 09 '14 at 13:59

2 Answers2

2

I'm guessing you are using SqlMembershipProvider as your membership provider?

You should just be able to use something like this:

MembershipUser u = Membership.GetUser("example@example.net");
txtPasswordChanged.Text = u.LastPasswordChangedDate.ToString("M/d/yyyy"); 
Keir
  • 483
  • 3
  • 10
1

You don't necessarily have to force users to change their passwords after some specific amount of time, but you can create a field in your table (where you store your user accounts), and update that every time the user change their password.

Though the examples you have found don't use this field for your purpose, but it is actually the right way to achieve what you want. You just have to update you password changing code to update that field as well.

bilal.haider
  • 318
  • 1
  • 4
  • 18