Create a user management system using membership and membershipuser

Source: Internet
Author: User

The membershipuser technology creates a simple user management system, which mainly enables user registration, user logon, and password change.

Adduser. aspx for user registration.

 

Login. aspx for Logon


Loginsuccess. aspx logon success page

Changepassword. aspx to change the logon User Password

The procedure is as follows:


1. Implement the user registration function.


1) on the "adduser. aspx" Page, enter the code to verify that the user is successfully added in the on_click event of the "Add User" button:

[Visual Basic]

Dim status as membershipcreatestatus

Membership. createuser (txtusername. Text, txtpassword. Text ,_
Txtemail. Text,Txtpasswordquestion. Text ,_

Txtpasswordanswer. Text, true, status)

If status = membershipcreatestatus. Success then

Response. Write ("user created successfully ")

End if

[C #]

Membershipcreatestatus status;

Membership. createuser (txtusername. Text, txtpassword. Text,
Txtemail. Text, txtpasswordquestion. Text, txtpasswordanswer. Text,
True, out status );

If (status = membershipcreatestatus. Success)

{

Response. Write ("User Added successfully ");

}

2) browse the "adduser. aspx" Page and create a new user. The user details are as follows:

Username: zhangsan

Password: P @ ssw0rd

Email: zhangsan@163.com

Password: My brother's birthday

Password answer: 19871212

Click "Add User". The page shows that the user has been added successfully. Open the Asp.net website management tool and we can see that the user you just added already exists. User Added successfully.


Note: if an error is displayed after you open the website management tool or you cannot create a user, check whether your folder is read-only. For example, set the site file to read/write, under the Security tab of the folder properties, add the user named ASPnet and set the user's permissions to full control.


2.

Implement User Login


1). Enter the verification login code in the on_click event of the login button on the "login. aspx" Page:

[Visual Basic]

If (membership. validateuser (txtusername. Text, txtpassword. Text ))

Session ["username"] = txtusername. Text

Response. Redirect ("loginsuccess. aspx ")

End if

[C #]

If (membership. validateuser (txtusername. Text, txtpassword. Text ))

{

Session ["username"] = txtusername. text;

Response. Redirect ("loginsuccess. aspx ");

}

2) browse the "login. aspx" Page and enter a user that does not exist. the user cannot log on successfully. Enter the user we created and click "login". The verification is passed and go to the "loginsuccess. aspx" page.

3. Change the User Password

1) on the changepassword. ASPX page, enter the code to change the logon user password in the on_click event of the Change Password button:

[Visual Basic]

Dim user as membership =_
Membership. getuser (session ["username"]. tostring ())

If (user. changepassword (txtoldpassword. Text ,_

Txtnewpassword. Text ))

Response. Write ("User Password Changed ")

End if

[C #]

Membershipuser user =
Membership. getuser (session ["username"]. tostring ());

If (user. changepassword (txtoldpassword. Text,
Txtnewpassword. Text ))

{

Response. Write ("User Password Changed successfully ");

}

2) browse the "login. aspx" Page and change the password of the created user zhangsan to "P @ ssw0rd1 ". Log On again with the new password, and the page passes verification. The password is successfully modified.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.