check name in xml file B4 MembershipProvider.CreateUser

F

Fossie

Hi,
I need to check that someone signing up is listed in an xml file. I am
using a customer membership provider for Access and trying to integrate
the xml check into that. Am I on the right track? The code below runs
but it results in "Your account was not created. Please try again."
It's obviously not picking up username and comparing it.

code.vb

' MembershipProvider.CreateUser
'

Public Overrides Function CreateUser(username As String, _
password As String, _
email As String, _
passwordQuestion As String, _
passwordAnswer As String, _
isApproved As Boolean, _
providerUserKey As Object, _
ByRef status As MembershipCreateStatus) As MembershipUser

Dim Args As ValidatePasswordEventArgs = _
New ValidatePasswordEventArgs(username, password, True)

OnValidatingPassword(args)

If args.Cancel Then
status = MembershipCreateStatus.InvalidPassword
Return Nothing
End If


If RequiresUniqueEmail AndAlso GetUserNameByEmail(email) <> ""
Then
status = MembershipCreateStatus.DuplicateEmail
Return Nothing
End If

Dim u As MembershipUser = GetUser(username, False)

If u Is Nothing Then
Dim createDate As DateTime = DateTime.Now

If providerUserKey Is Nothing Then
providerUserKey = Guid.NewGuid()
Else
If Not TypeOf providerUserKey Is Guid Then
status = MembershipCreateStatus.InvalidProviderUserKey
Return Nothing
End If
End If


'........start xml

Dim strUser As String = username
Dim blnIsAuthenticated As Boolean
Dim objXMLDoc As New XMLDocument()
Try
objXMLDoc.Load("\Administration\dbs\clientids.xml")
Catch objError As Exception
status = MembershipCreateStatus.ProviderError
End Try

Dim UserNodes As XmlNodeList
UserNodes = objXMLDoc.GetElementsByTagName(username)

'see if we found an element with this username
If Not UserNodes Is Nothing Then
Dim blnUserExists As Boolean = True
Dim strUserCheck As String = username
Try
strUserCheck = UserNodes(0).FirstChild().Value
Catch objError As Exception
status = MembershipCreateStatus.ProviderError
blnUserExists = False
End Try

If blnUserExists = True Then
blnIsAuthenticated = True
Else
status = MembershipCreateStatus.ProviderError

End if
End If

If blnIsAuthenticated Then

'...... into database code .....


Dim conn As OdbcConnection = New
OdbcConnection(connectionString)
Dim cmd As OdbcCommand = New OdbcCommand("INSERT INTO [" &
tableName & "]" & _
" (PKID, Username, Password, Email, PasswordQuestion, " &
_

etc ...... code cut

Try

conn.Open()

Dim recAdded As Integer = cmd.ExecuteNonQuery()

If recAdded > 0 Then
status = MembershipCreateStatus.Success
Else
status = MembershipCreateStatus.UserRejected
End If
Catch e As OdbcException
If WriteExceptionsToEventLog Then
WriteToEventLog(e, "CreateUser")
End If

status = MembershipCreateStatus.ProviderError
Finally
conn.Close()
End Try
'.....
End if
'......

Return GetUser(username, False)
Else
status = MembershipCreateStatus.DuplicateUserName
End If

Return Nothing
End Function

clientids.xml
<?xml version="1.0"?>
<username>
<foster></foster>
<jessie></jessie>
<shadow></shadow>
</username>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top