Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


check the password entered macthes one on a external file

Posted on 2004-10-26
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 19

Expert Comment

ID: 12409222
?? Could not get you

LVL 12

Author Comment

ID: 12409426
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 asp.net not c thanks
LVL 19

Expert Comment

ID: 12409658
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

Accepted Solution

The_Biochemist earned 2000 total points
ID: 12409807
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

618 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