ASP.NET Web Pages – Logout and Change Password Page

[ This is an 8 part tutorial, previous tutorial: Reset Password ]


In the Logout page add the following:


This is not very difficult: it will log the user out and redirect them to the login page. You can choose to redirect to the home page if you wish.

Change Password Page

In the Change Password page add the following:

var message = "";
if (IsPost)
    var currentPassword = Request["currentPassword"];
    var Password = Request["Password"];
    var ConfirmPassword = Request["ConfirmPassword"];
    Validation.RequireFields("currentPassword", "Password", "ConfirmPassword");
    Validator.StringLength(16, 6)
    if (ConfirmPassword != Password)
    Validation.AddFormError("Sorry passwords do not match");
Similar to the previous pages get user submitted data and validated it. 
    if (Validation.IsValid())
        if (WebSecurity.ChangePassword(WebSecurity.CurrentUserName, currentPassword, Password))
            message= "Password has been changed";
        } else {
            Validation.AddFormError("Current password is wrong");

If the data is valid change the password. It takes 3 arguments: username (which is the current logged in user), current password and new password.


<form method="post">
<label>Current Password</label>
<input type="password" name="currentPassword" />
<input type="password" name="Password" />
<label>Confirm Password</label>
<input type="password" name="ConfirmPassword" />
<input type="submit" value="Change Password"/>

[ Continue, Account Management ]