iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 17, 2008
Learn HTML forms
About
 
May 16, 2008
Who Are Your Top Friends on Facebook?
About
 
May 15, 2008
Reader Question - Would you host your client's work on your website?
About
 
May 15, 2008
How to Create an Ajax Autocomplete Text Field: Part 6
WebReference.com
 
May 14, 2008
Poll: Are the browser safe colors still needed?
About
 
May 14, 2008
Google Doctype launched
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /ASP.NET

Forms Authentication Against An XML File 

  Views:    7912
  Votes:    0
by ORCS WEB, Inc. 5/14/05 Rating: 

Synopsis:

This code shows how to validate against an XML file for Forms Authentication security in ASP.Net.
Pages: 
The Article

Please read one of the earlier articles on Forms Authentication for an introduction and to see the required settings in the web.config file. The code below is just a modification of the login.aspx page. 
<%@Page Language="VB" Trace="false"%>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Xml" %>
<script language="VB" runat=server> 
  Sub ValidateLogin(Src as Object, E as EventArgs)
  Dim sXmlPath As String = "C:\Inetpub\wwwroot\users.xml"   
  Dim oXmlDoc As New XmlDocument()   
  Try     
    oXmlDoc.Load(sXmlPath)   
  Catch oError As Exception
     StatusMessage.innerHTML = "There was an error:<BR>" & oError.Message & "<BR>" _
       & oError.Source & "."     
     Exit Sub   
   End Try   
   Dim oXmlUser As XmlNodeList   
   oXmlUser = oXmlDoc.GetElementsByTagname(txtUser.Value)
   If Not (oXmlUser Is Nothing) Then
     If txtPwd.Value = oXmlUser(0).FirstChild().Value Then
        FormsAuthentication.RedirectFromLoginPage(txtUser.Value, false)
      Else
       StatusMessage.InnerHtml = "Invalid login"
     End If
    End If
  End Sub
</script>
<html>
<head>
  <title>Forms Authentication Against An XML File</title>
</head>
<body>
<form method="post" runat="server">
  Username: <INPUT type="text" name="txtUser" id="txtUser"runat="server"/><BR>
  Password: <INPUT type="password" name="txtPwd" id="txtPwd"runat="server"/><BR>
<INPUT type="submit" OnServerClick="ValidateLogin" runat="server"/>
</form>
<SPAN id="StatusMessage" runat="server"/>
</body>
</html>
Here is the XML file used to hold the usernames and passwords. 
<?xml version="1.0" ?><users>  <!-- format is <username>password</username> -->  
<user1>pass1</user1>  <user2>pass2</user2>  <user3>pass3</user3></users>
~Brad
Brad Kingsley is founder and president of ORCS Web, Inc. - a company that provides managed hosting services for clients who develop and deploy their applications on Microsoft Windows platforms. 
<%@Page Language="VB" Trace="false"%>
<%@ Import Namespace="System.Web.Security" %> <%@ Import Namespace="System.Xml" %> <script language="VB" runat=server>
Pages: 

Similar/related articles:


 
  Sponsors