Using Forms Authentication in Asp.NET
Hi All,
To use form authentication in asp.net application
1- Create a new website
2- Change the name of the default.aspx to login.aspx
3- Add 2 labels one for username and password and two textboxes name txtUserName and txtPassword
and a button named btnLogin with label Login.
4 -Put the following in the web.config page
<authentication mode=”Forms”>
<forms loginUrl=”login.aspx”>
<credentials passwordFormat=”Clear”>
<user name=”Mickey” password=”Mouse”/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users=”?”/>
</authorization>
5-Put this code in the btnLogin click’s event handler.
protected void btnLogin_Click(object sender, EventArgs e)
{
if(FormsAuthentication.Authenticate(txtUserName.Text,txtPassword.Text))
{
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false);
}
else
{
lblInfo.Text = “you are not authorized to view the page”; // add one more label lblInfo }
}
6- That’s it your page should work now
We can add more users within the credential section of web.config
We can even encrypt the password we are saving in the web.config
We can even make use of cookie for the same.
Looking forward to include the code for the same
Bye
This was originally posted here.

Like
Report
*This post is locked for comments