mtaylor314
Member
I need some help authenticating through an XML file. The .XML has the following format
I use this code to read and authenticate
This only allows me to login in the first user, any other user apparently does not exist. Any pointers would be appreciated
I then tried this code as authentication, but it does not allow any user to log in. It will go through the For/Next loop once and the value of node.tostring is "System.Xml.XmlElement"
HTML:
<USERS>
<user1>pw</user1>
<user2>pw</user2>
...
</USERS>
VB.NET:
Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As _
System.Web.UI.WebControls.AuthenticateEventArgs) _
Handles Login1.Authenticate
'Using xTR As XmlTextReader = New XmlTextReader(Server.MapPath("Data Files\UserData.xml"))
Dim strUser As String = FTPSite & "UserData.xml"
Dim settings As New XmlReaderSettings()
settings.IgnoreComments = True
settings.IgnoreWhitespace = True
settings.IgnoreComments = True
Dim reader As XmlReader = XmlReader.Create(strUser, settings)
Using reader
Try
reader.ReadStartElement("USERS")
Try
reader.ReadStartElement(Login1.UserName.ToUpper)
If reader.Value.CompareTo(Login1.Password) = 0 Then
e.Authenticated = True
Exit Sub
End If
Login1.FailureText = "Invalid Password"
Catch ex As Exception
Login1.FailureText = "Invalid User Name"
End Try
Catch ex As Exception
Login1.FailureText = "Unable to read UserData file. Err: " & ex.Message
End Try
End Using
End Sub
I then tried this code as authentication, but it does not allow any user to log in. It will go through the For/Next loop once and the value of node.tostring is "System.Xml.XmlElement"
VB.NET:
Try
Dim oXmlDocument As New XmlDocument
Dim NodeList As XmlNodeList
oXmlDocument.Load(FTPSite & "UserData.xml")
NodeList = oXmlDocument.SelectNodes("/USERS")
For Each Node As XmlNode In NodeList
If Node.ToString.ToUpper = Login1.UserName.ToUpper Then
Try
If Node.InnerText.CompareTo(Login1.Password) = 0 Then
e.Authenticated = True
Exit Sub
End If
Login1.FailureText = "Invalid Password"
Catch ex As Exception
Login1.FailureText = "Invalid User Name"
End Try
End If
Next
Catch ex As Exception
Login1.FailureText = "Unable to read UserData file. Err: " & ex.Message
End Try
Last edited: