Change password using Forms Authentication

D

divati

Check last date of change password every login than count 30 days or 90
days.

DateTime LastChangePassword;
int DayOfPassword;

LastChangePassword.AddDays(DayOfPassword);

if (LastChangePassword > DayOfPassword)
{
Response.Redirect("ChangePassword.aspx");
}
 
F

Felix Melendez

Hi there! I'd like to know if anyone out there can give me a helping hand.
I've developed an asp.net application that uses Forms Authentication.

Question:

I'd like to give users the ability that after every 30 days, they must
change their passwords. So if the 30 days have passed, and user FELIX tries
to log on, I want this user to be redirected to a ChangePwd.aspx web page.
Once the user changes his/her password, he/she must be taken back to the
login screen so that he/she can log on with his/her new password.

Any one has an idea on how to do this? sample code?

Thanks in advance,



Felix
 
F

Felix Melendez

divati,

First of all, I'd like to thank for the quick response.

On the other hand, I'd tried your solution before posting the question. I
think that it'd be better to explain in detail of what I've done so far.

Here's the code I've written on the cmdLogin_ServerClick() event procedure:

If Page.IsValid Then
Dim accountSystem As New
ClubCorporativoCOM.Versatec.ClubCorporativo.Seguridad
Dim userId As String =
accountSystem.LoginIsValid(txtUserName.Value, txtUserPass.Value)
If userId = "1" Then
Dim objPWD As New
ClubCorporativoCOM.Versatec.ClubCorporativo.Seguridad, intRetCode As
Integer, strRetMessage As String
objPWD.VerificaPWD(txtUserName.Value, intRetCode,
strRetMessage)
If intRetCode = 0 Then
Response.Redirect("CambiarPWD.aspx") <== HERE'S THE
ERROR!!!
End If

FormsAuthentication.SetAuthCookie(txtUserName.Value, False)
If
CType(ConfigurationSettings.AppSettings("useDefaultPageFromLogin"), Boolean)
= False Then
Response.Redirect(ConfigurationSettings.AppSettings("redirectDefaultUrl").ToString)
Else
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUserName.Value,
False))
End If
Else
Me.lblMsg.Visible = True
Me.lblMsg.Text = "<" & "br" & ">" & strErrMsg & "<" & "br" &
">"
End If
End If

The problem lied as soon as I executed the response.redirect method because
it took me again to the logon web page. Why??? please, continue reading...
But then I studied the code line by line and found out that the infamous
error was the line:
FormsAuthentication.SetAuthCookie(txtUserName.Value, False)
had to be called before the lines:
If intRetCode = 0 Then
Response.Redirect("CambiarPWD.aspx") <== HERE'S THE
ERROR!!!
End If

The reason for this I guess was that, by the time the response.redirect line
was called the user had not yet been authenticated and therefore,
FormsAuthentication module redirected me to the logon screen. So first I
had to be authenticated, then create the cookie (by the SetAuthCookie
method) and then... had to redirect to the CambiarPWD.aspx to proceed by
changing the password.

At the end, it worked great!.

Thanks again for the help and patience.
Felix
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top