check the password entered macthes one on a external file

can anyone make this work, i did it to do somthing very simple like check the password entered macthes one on a external file called pass.tx, if it does go to a page if not give a message. can anyone help.

here is what i have so far.

<script language="VB" runat="server">

Sub Submit_Click(Sender as Object, e as EventArgs)
dim dr as String

dr = "test"


  Session("email") = Nothing
            Response.Write("Message from load event handler!")
        Session("email") = dr
If Not (Session("email") = Nothing) Then
End If
end sub
LVL 12
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

?? Could not get you

pigmentartsAuthor Commented:
Very sorry will try and explain

I need a simple program that allows a client to log into a page if they have the right password. The password will be stored in a txt file call pass.txt. Ignore the above code. Would any one show me some example code on how to achieve this? Thanks

Ps I am working in vb not c thanks
How do you know that he has supplied the right Password
I assume you need to check from a database table called User_Login

Sub Submit_Click(Sender as Object, e as EventArgs)

       If ValidLogin() Then
            'You can store the ID in Session so that it can be checked on other pages
            'Session.Add("UID", TxtUserID.Text)
            'Store the User ID & Pwd in a File
            Dim FNo As Integer = FreeFile()
            FileOpen(FNo, "Pass.txt", OpenMode.Append, OpenAccess.Write)
            WriteLine(FNo, "User=" & TxtUserID.Text & " Pwd=" & TxtPassWord.Text)
        End If

   Private Function ValidLogin() As Boolean
        ValidLogin = False
        Dim Cn As OleDbConnection = New OleDbConnection(YourConnStr)
        Dim Rdr As OleDbDataReader
        Dim CmdText As String = "Select Password From User_Login Where UserName='" & TxtUserID.Text& "'
        Dim Cmd As OleDbCommand = New OleDbCommand(CmdText, Cn)
            Rdr = Cmd.ExecuteReader
            If Rdr.HasRows() andAlso Rdr(0) = TxtPassWord.Text Then
                   Return True
                   Return False
            End If
    End Function

End Sub
Two comments...

1) Using a text file to store sensitive passwords is not the best way to do it
2) However, rather than using a text file I would try an XML file as they are easier to work with I find...

For an xml example you could try this (P.S. this is an overly simplified example of an XML file but works in this case)

1) Create an xml with the contents below (you can use notepad and save it as .xml)

<?xml version="1.0" encoding="utf-8" ?>
<Password>Not Telling You!</Password>

2) Then use this code to read the file, set two variables (username and password), compare the values and redirect them to the page you want.

            'Dimension the XML Reader and storage variables
            Dim strUserName As String
            Dim strPassword As String
            Dim xmlReader As System.Xml.XmlTextReader
            'Instantiate the reader and locate file
            xmlReader = New System.Xml.XmlTextReader("C:\Test.xml") 'Alter filename to suit
            'Get the reader to parse all of the records and select the name of the elements you want
            Do While xmlReader.Read
                Select Case xmlReader.Name
                    'if it finds an element called UserName
                    Case "UserName"
                        strUserName = xmlReader.ReadInnerXml
                        'if it finds an element called Password
                    Case "Password"
                        strPassword = xmlReader.ReadInnerXml
                End Select
                'loop to next element
            'close the reader and release the file
'compare your password to the one from the file (strMYPASSWORD needs to be a string with the
'password that was given on the form)
if strMYPASSWORD = strPassword then
end if
        Catch ex As Exception

        End Try

You can also import system.xml in order to be able to remove it from the above code

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.