Cobold
Cobold

Reputation: 2613

Getting User Name and Password

I'm trying to create a login prompt. I have a xml file like this:

<Users>
 <User Name=User1 Password=Pass1/>
 <User Name=User2 Password=Pass2/>
</Users>

How to find if a UserName which is entered in a textbox exists in the file and find if the password is entered correctly? If there's a better way than using xml, can you provide any info?

Upvotes: 1

Views: 1579

Answers (3)

Searush
Searush

Reputation: 634

This code is in VB 6 (only InStr function) but you can understand it or convert it to VB.Net if you have Artinsoft converter. Try this (without any XML helpers):

Function CheckLoginPassword( UserName, Password)
   Dim l as string, allText as string
   l="<User Name=" & UserName & " Password=" & Password & "/>"
   '... HERE write code which will copy your XML's contents to variable allText
   If InStr(1,allText,l)>0 then 
       CheckLoginPassword=True
   Endif
End Function

After this you can write anywhere:

If CheckLogin (txtUserName.Text, txtPassword.Text)=true then ... else ...

Upvotes: 0

Jimmy Collins
Jimmy Collins

Reputation: 3304

There are many ways to do this, but are you saying that you're storing the password as plain text in an XML file? This isn't a good practice. You should at least be encrytping the password.

If you insist on doing it this way, check out LINQ To XML, which you could use to read the password from the correct user, and compare it to the one input.

With regards your question of doing this a better way, is this a desktop app or web app?

Upvotes: 2

Related Questions