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"); 
有帮助吗?

解决方案

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"); 

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top