User info : Membership « Login Security « ASP.Net

ASP.Net
1. ADO.net Database
2. Ajax
3. Asp Control
4. Collections
5. Components
6. Data Binding
7. Development
8. File Directory
9. HTML Control
10. Language Basics
11. Login Security
12. Mobile Control
13. Network
14. Page
15. Request
16. Response
17. Server
18. Session Cookie
19. Sitemap
20. Theme Style
21. User Control and Master Page
22. Validation by Control
23. Validation by Function
24. WebPart
25. WPF
26. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.Net » Login Security » Membership 
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.TextAnd txtNewPassword.Text <> "" Then
            If user.ChangePassword(txtCurrentPassword.Text, txtNewPassword.TextThen
                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.TextThen
                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
1. Displaying the number of users online
2. Membership.CreateUser
3. Membership.GetUser
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.