Forms Authentication – Managing Users

E05C0059

While there are a lot of controls available in ASP.NET that allow you to manage forms authentication, one control that doesn’t exist is something that will allow you to manage your user list.

Most of the time you don’t need this, but when you do, there is an obvious hole.

Since we need to write this code ourselves, how do access the user list from our code?

The Membership API built into ASP.NET gives you access to the user information and a lot more.

To access the list of users, you’ll need to call Membership.GetAllUsers();

Since I like working with datasets because of their flexibility, I create a DataTable that has the information I want to store and loop through the collection that Membership.GetAllUsers() returns and fill the DataTable.

DataSetContentEditors.LoginsDataTable logins =
    new DataSetContentEditors.LoginsDataTable();
MembershipUserCollection muc = Membership.GetAllUsers();
foreach (MembershipUser mu in muc)
{
    logins.AddLoginsRow(mu.UserName);
}

To change the password for the user, you can call the MembershipUser’s ResetPassword to generate a new password and then call the ChangePassword() method to set it to what you want it to be.


MembershipUser u = Membership.GetUser(userName);
string resetPassword = u.ResetPassword();
u.ChangePassword(resetPassword, newPassword);

Other Related Items:

Don't Mess With Me, I am a Programmer - T-Shirt (40 colors)Don't Mess With Me, I am a Programmer - T-Shirt (40 colors)Cotton T-Shirt 5.6 oz., heavyweight 100% preshrunk cotton T-shirt, Quarter-turned. Seamless collar, Taped shoulder-to-shoulder, Double-needle stitched neck, sleeves and hemmed bottom. Direct printed on Front of T-Shirt, this is not a transfer. Won't peel or crack in washer/dryer.
MCTS Self-Paced Training Kit (Exam 70-562): Microsoft .NET Framework 3.5-ASP.NET Application Development: Microsoft(r) .Net Framework 3.5 ASP.Net Application Development (Pro - Certification)MCTS Self-Paced Training Kit (Exam 70-562): Microsoft .NET Framework 3.5-ASP.NET Application Development: Microsoft(r) .Net Framework 3.5 ASP.Net Application Development (Pro - Certification)

Ace your preparation for the skills measured by MCTS Exam 70-562—and on the job. Work at your own pace through a series of lessons and reviews... Read More >

Related Post

Comments are closed.

DotNetNuke Sponsor

 

Most Valuable Blogger
Sponsor