User info
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="UserInfo_aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
UserID</td>
<td>
<asp:TextBox ID="txtUserID" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Current Password</td>
<td>
<asp:TextBox ID="txtCurrentPassword" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
New Password</td>
<td>
<asp:TextBox ID="txtNewPassword" runat="server" TextMode="Password"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnChangePassword" runat="server" Text="Change Password"/></td>
</tr>
<tr>
<td>
Password Question</td>
<td>
<asp:TextBox ID="txtPasswordQuestion" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnChangePasswordQuestion" runat="server" Text="Change Question"
UseSubmitBehavior="False" /></td>
</tr>
<tr>
<td>
Password Answer</td>
<td>
<asp:TextBox ID="txtPasswordAnswer" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Email</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnUpdateEmail" runat="server" Text="Update Email"/></td>
</tr>
</table>
</div>
</form>
</body>
</html>
File: Default.aspx.vb
Partial Class UserInfo_aspx
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Me.Load
Dim user As MembershipUser
user = Membership.GetUser
Response.Write("You last login on: " & user.LastLoginDate & "<br/>")
Response.Write("Your account was created on: " & user.CreationDate & "<br/>")
Response.Write("Your password was last changed on: " & user.LastPasswordChangedDate & "<br/>")
If Not IsPostBack Then
txtUserID.Text = user.UserName.ToString
txtPasswordQuestion.Text = user.PasswordQuestion
txtEmail.Text = user.Email
End If
End Sub
Protected Sub btnChangePassword_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles btnChangePassword.Click
Dim user As MembershipUser = Membership.GetUser
If txtCurrentPassword.Text <> "" And _
(txtNewPassword.Text <> txtCurrentPassword.Text) And txtNewPassword.Text <> "" Then
If user.ChangePassword(txtCurrentPassword.Text, txtNewPassword.Text) Then
displayMessage("Password Changed.")
Else
displayMessage("Password Changed Failed.")
End If
Else
displayMessage("Required fields missing")
End If
End Sub
Private Sub displayMessage(ByVal str As String)
Response.Write(str)
End Sub
Protected Sub btnChangePasswordQuestion_Click( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles btnChangePasswordQuestion.Click
Dim user As MembershipUser = Membership.GetUser
If txtCurrentPassword.Text <> "" And _
txtPasswordQuestion.Text <> "" And _
txtPasswordAnswer.Text <> "" Then
If user.ChangePasswordQuestionAndAnswer( _
txtCurrentPassword.Text, _
txtPasswordQuestion.Text, _
txtPasswordAnswer.Text) Then
displayMessage("Password Question Changed.")
Else
displayMessage("Password Question Failed.")
End If
Else
displayMessage("Required fields missing")
End If
End Sub
Protected Sub btnUpdateEmail_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles btnUpdateEmail.Click
Dim user As MembershipUser = Membership.GetUser
user.Email = txtEmail.Text
Membership.UpdateUser(user)
displayMessage("Email Updated.")
End Sub
End Class
Related examples in the same category