The Login Page

0
10

The Login Page After the web.config file is created, authentication mode and authorization rules have been specified. The next step is to create a web form page (Login Page.aspx) for your application that requests information from the user and decides whether the user should be authenticated.After the web.config file is created, authentication mode and authorization rules have been specified. The next step is to create a web form page (Login Page.aspx) for your application that requests information from the user and decides whether the user should be authenticated.
ASP.NET provides a special FormsAuthentication class in the System.Web.Security.namespace, which uses static methods that helps and manages the process.
Here are some most important methods of the Forms Authentication Class that has been described.
Member DescriptionFormsCookieName It is a read-only property that provides the name of the forms authentication cookie.FormsCookiePath It is a read-only property that provides the path set for the forms authentication cookie.Authenticate() It checks a user name and password against a list of accounts that can be entered in the web.config file.RedirectFromLoginPage() It logs the user into an ASP.NET application by creating the cookie, attaching it to the current response, and redirecting the user to the page originally requested.SignOut() It logs the user out of the ASP.NET application by removing the current encrypted cookie.SetAuthCookie() It logs the user into an ASP.NET application by creating and attaching the forms authentication cookie. Unlike the RedirectFormLoginPage () method, it does not take the user back to the initially requested page.GetRedirectUrl() It provides the URL of the originally requested page. You could use this with SetAuthCookie () to log a user into an application and make a decision in your code whether to redirect to the requested page or use a more suitable default page.GetAuthCookie() It creates the authentication cookie but does not attach it to the current response.you can perform additional cookie customization and then add it manually to the response.HashPasswordForStoringInConfigFile() It encrypts a string of text using the specified algorithm. This hashed value provides a secure way to store an encrypted password in a file or database. Now you have to create a login Page named as login page.aspx and also change the settings in the Web.Config file.
Firstly, we will make changes in the Web.Config File.
CodeView for the Web.Config File
Fig 5.
Now you have to create a Login page having Two Textboxes, Two Labels, and one Button control. You also need to change its text property like
Label1 text property is “User Name”.Label2 text property is “Password”.Button1 Text Property is “Login”.Text property for both the Textboxes should be blank.
Here you will see one more label that is used to popup a message whether the password is correct or not.
DesignView
Fig 6.
CodeView of a login page (login Page.aspx)
Fig 7.
CodeBehindView
Fig 8.
Output
Fig 9.
When the user clicks the login button, the page checks whether the user has typed the password which has been specified in the code and uses the RedirectFormLoginPage () method to log the user in. If the password is incorrect it will show a message “Invalid Password”. so here in this example you will see that the user entered the password”CSITQuestion” which does not match with the password given in the code behind file so it pop up a message”Invalid Password”.