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"

email=request.form("email")

  Session("email") = Nothing
       
            Response.Write("Message from load event handler!")
            Response.Write(dr)
            
            
        Session("email") = dr
     
                        
If Not (Session("email") = Nothing) Then
      
    Response.Write("right")      
   Else
   
   Response.Write("wrong")       
End If
end sub
</script>
LVL 12
pigmentartsAsked:
Who is Participating?
 
The_BiochemistConnect With a Mentor Commented:
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" ?>
<Users>
<UserName>The_Biochemist</UserName>
<Password>Not Telling You!</Password>
</Users>

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.

 Try
            '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
            Loop
            'close the reader and release the file
            xmlReader.Close()
'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
server.transfer("/AcceptedPage.aspx")
else
server.transfer("/RejectedPage.aspx")
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
0
 
arif_eqbalCommented:
?? Could not get you

0
 
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 asp.net not c thanks
0
 
arif_eqbalCommented:
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)
            FileClose(FNo)
            Response.Redirect("Valid_User_Home.aspx")
        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)
            Cn.Open()
            Rdr = Cmd.ExecuteReader
            Rdr.Read()
            If Rdr.HasRows() andAlso Rdr(0) = TxtPassWord.Text Then
                   Return True
            Else
                   Return False
            End If
    End Function


End Sub
0
All Courses

From novice to tech pro — start learning today.