check the password entered macthes one on a external file

Posted on 2004-10-26
Last Modified: 2010-04-23
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
Question by:pigmentarts
    LVL 19

    Expert Comment

    ?? Could not get you

    LVL 12

    Author Comment

    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
    LVL 19

    Expert Comment

    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
    LVL 6

    Accepted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Product Review - Android Remix

    Come along for the ride with our Senior Product Manager, Brian Matis, as he reviews the Android Remix.

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now