BESTPROOFINGSERVICE.COM

amended proof of service - www.bestproofingservice.com

Menu


The great thing about the Web.Config file is that it is flexible enough to allow you to store usernames and passwords in it. The following


code added to the forms element of the Web.Config file sets credentials for the user zak:   <configuration> <system.web> <authentication mode="Forms"> <forms> <credentials passwordFormat="Clear"> <user name="zak" password="zak" /> </credentials> </forms> </authentication> <authorization> <deny users="?" /> </authorization> </system.web> </configuration>   You can now modify the code that lies in the head of your login page to validate the usernames and passwords against the Web.Config file. The result resembles the following:   <script runat="Server"> Sub Authenticate(s As Object, e As EventArgs) If FormsAuthentication.Authenticate(username.Text, password.Text) Then FormsAuthentication.RedirectFromLoginPage(username.Text, False) End If End Sub </script>   Although most of the code is similar to what you added a few sections ago, the following line is different:   If FormsAuthentication.Authenticate(username.Text, password.Text) Then   In this case, we use the Authenticate() method of the FormsAuthentication class, passing in the values of the username and password TextBox controls as parameters. The Authenticate() method is interesting in that it automatically performs the validation against the credentials outlined in the <forms> tag in the Web.Config file. Trying saving both the Web.Config and login.aspx pages and test the results in the browser by pressing the F12 key. You'll notice that the login functionality is transparent. The difference, of course, is how we're storing the username and password. Rather than hard-coding the username and password in the code of the login.aspx page, we're storing it in the Web.Config file, making it more flexible down the line. If we wanted to, we could add as many users as we needed by simply adding a new <user> tag below or above the existing value as follows:   <forms> <credentials passwordFormat="Clear"> <user name="zak" password="zak" /> <user name="jessica" password="jessica" /> <user name="makenzie" password="makenzie" /> <user name="zaven" password="zaven" /> </credentials> </forms>   Database Authentication