What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » VB Help [Another problem]

Pages: (2): « First [ 1 ] 2 » Last »
VB Help [Another problem]
Author: Message:
Reaper
Veteran Member
*****

Avatar

Posts: 1393
Reputation: 23
35 / Male / Flag
Joined: Jun 2004
O.P. VB Help [Another problem]
im working on my A2 computing project, and i want to put a login dialog on my system.
so far ive used the template they have given me for the pag and the design.
i want to know how to search the file for the user name and password and where in the code i do all this

code:
Option Explicit

Public LoginSucceeded As Boolean

Private Sub cmdCancel_Click()
    'set the global var to false
    'to denote a failed login
    LoginSucceeded = False
    Me.Hide
End Sub

Private Sub cmdOK_Click()
    'check for correct password
    If txtPassword = "password" Then
        'place code to here to pass the
        'success to the calling sub
        'setting a global var is the easiest
        LoginSucceeded = True
        Me.Hide
    Else
        MsgBox "Invalid Password, try again!", , "Login"
        txtPassword.SetFocus
        SendKeys "{Home}+{End}"
    End If
End Sub


this is the code given by the VB app

This post was edited on 09-15-2005 at 05:15 PM by Reaper.
09-13-2005 06:01 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: VB Help
code:
Dim strUsername, strPassword as string

Open "text1.text" For Input As #1
Do Until EOF(1)
     Input#1, strUsername, strPassword
     If strUsername = txtUsername And strPassword = txtPassword Then
          'Do stuff if password and username match
          Exit Do
     End If
Loop
Close#1

This post was edited on 09-13-2005 at 06:49 PM by matty.
09-13-2005 06:48 PM
Profile E-Mail PM Find Quote Report
Reaper
Veteran Member
*****

Avatar

Posts: 1393
Reputation: 23
35 / Male / Flag
Joined: Jun 2004
O.P. RE: VB Help
text1.text is the name of the file. do i put the whole path name or just the name of the file?

also what do i wrrite in the text file so it identifies the username and password. so bascially what do i wirte in the text file if the username is Guest and the password is qwerty

This post was edited on 09-13-2005 at 07:00 PM by Reaper.
09-13-2005 06:52 PM
Profile E-Mail PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: VB Help
Most of the time you need the full name to the file. As for writing the username and password, use comma-separated values (or maybe the pipe | character). I also recommend hashing the password before storing it - you won't need MD5, a simple hash like the one MSN uses to encode e-mail addresses will suffice.
[Image: spartaafk.png]
09-13-2005 09:14 PM
Profile PM Web Find Quote Report
Reaper
Veteran Member
*****

Avatar

Posts: 1393
Reputation: 23
35 / Male / Flag
Joined: Jun 2004
O.P. RE: VB Help
ok i got a few problems, when i type guest, qwerty in the file it doesnt login in.
when i put just guest in the file, i get the error: Run-time error "62"
Input past end of file

when i click debug, the line Input #1, strUsername, strPassword is highlighted. when i put my mouse over strUsername, it ses strUsername = "guest" but when i do it over strPassword it says strPassword""

also the pipe character doesnt work
09-13-2005 10:00 PM
Profile E-Mail PM Find Quote Report
brian
Senior Member
****

Avatar

Posts: 819
Reputation: 43
– / Male / –
Joined: Sep 2004
RE: VB Help
How do you mean doesn't work, what you are supposed to do is:

make a file with "guest|qwerty" in it
open the file, loop through it, split each LINE with |.
each line will have a user/pass, so you choose the line/user you need and get its pass, then check.
09-13-2005 10:25 PM
Profile PM Find Quote Report
Reaper
Veteran Member
*****

Avatar

Posts: 1393
Reputation: 23
35 / Male / Flag
Joined: Jun 2004
O.P. RE: VB Help
i just wanna test it with the one login info, so i dont need to do the loop and split do i?

what i got in the file is:

guest|qwerty

nothing else

btw if u want the code i have got, it is:
code:
Option Explicit

Public LoginSucceeded As Boolean

Private Sub cmdCancel_Click()
    'set the global var to false
    'to denote a failed login
    LoginSucceeded = False
    Me.Hide
End Sub

Private Sub cmdOK_Click()
    'check for correct password
    If txtPassword = "password" Then
        'place code to here to pass the
        'success to the calling sub
        'setting a global var is the easiest
        LoginSucceeded = True
        frmMainMenu.Show
        Me.Hide
            Else
        MsgBox "Invalid Password, try again!", , "Login"
        txtPassword.SetFocus
        SendKeys "{Home}+{End}"
    End If
End Sub

Private Sub Form_Load()
Dim strUsername, strPassword As String

Open "C:\Documents and Settings\Kevish\My Documents\A2 Computing Coursework\login.txt" For Input As #1
Do Until EOF(1)
     Input #1, strUsername, strPassword
     If strUsername = txtUserName And strPassword = txtPassword Then
          'Do stuff if password and username match
          Exit Do
     End If
Loop
Close #1
End Sub


This post was edited on 09-13-2005 at 10:33 PM by Reaper.
09-13-2005 10:29 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: VB Help
Heres an example for you.

.zip File Attachment: Example.zip (1.62 KB)
This file has been downloaded 122 time(s).
09-13-2005 11:08 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: VB Help
quote:
Originally posted by raceprouk
Most of the time you need the full name to the file.
Unless you execute the program from within the same folder as where the file is, you always need the give the full path.

quote:
Originally posted by raceprouk
As for writing the username and password, use comma-separated values (or maybe the pipe | character).
It depends on how you're going to read the file. If you use the "Input" command, then you must seperate the fields with a comma. If you use the "Line Input" command (which reads a whole line instead until the next delimeter), it doesn't matter what you use to seperate it as long as you use that same seperator in your code when you extract the parts you need from it (Matty's code) or use it to build up your comparisson string (my alternative code).

quote:
Originally posted by Reaper66613
ok i got a few problems, when i type guest, qwerty in the file it doesnt login in.
Not because you entered something wrong in the file or read it out wrongly (aka the reading routine). It is because you didn't handle it correctly higher-up in your code. See my notes below about your code...

quote:
Originally posted by Reaper66613
when i put just guest in the file, i get the error: Run-time error "62"
Input past end of file.
when i click debug, the line Input #1, strUsername, strPassword is highlighted. when i put my mouse over strUsername, it ses strUsername = "guest" but when i do it over strPassword it says strPassword""
Because there was 1 field missing in the file.

quote:
Originally posted by Reaper66613
also the pipe character doesnt work
That doesn't work when you use "Input #1, Variable1, Variable2". If you use that then you need 2 fields in the file. A pipe symbol doesn't qualify as a delimeter, only a comma does (when reading field by field).

If you wanna use a pipe symbol you need to read the whole line at once with "Line Input #1, Variable". In fact instead of a pipe symbol you can use whatever character you like (or none at all for that matter) as the line is interpreted as a whole, not as seperate fields...

quote:
Originally posted by brian
How do you mean doesn't work, what you are supposed to do is:
It didn't work because he is using "Input", and not "Line Input".

quote:
Originally posted by brian
make a file with "guest|qwerty" in it
open the file, loop through it, split each LINE with |.
each line will have a user/pass, so you choose the line/user you need and get its pass, then check.
Much to complicated (not to mention slow string and/or array manipulations). You don't need to split anything and then check each fields individually. See my alternative code.

quote:
Originally posted by Matty
Heres an example for you.
It contains a big bad wolvebug :P You forgot to close your file when a match is found ;)


-----------------------------------------


Reaper66613, about your posted Form code:

1) Since you used "Input #1, strUsername, strPassword", login.txt needs to contain:
code:
guest,qwerty
2) You need to adapt many other parts of the example code to let it work eventually. What people have provided for you in this thread here is the base for checking a file with some login info: the basic open file and checking for some matches. You need to adapt the example source from VB to incooperate that. Aka adapt the cmdOK_Click() routine because at the moment the file login.txt is simply read out when you load the form and checked against empty strings as you don't have anything entered yet in the textboxes (because the form isn't shown yet).

The code provided in this thread does not go into the Form_Load procedure but must be incooperated into cmdOK_Click()...

Also:
code:
Dim strUsername, strPassword As String
is the same as
code:
Dim strUsername As Variant
Dim strPassword As String
and not, as intended, as
code:
Dim strUsername As String
Dim strPassword As String
Never declare variables on one line, unless you state for each individual one the proper data type. strUsername is declared "As Variant" because there is no explicit data type given.


-----------------------------------------


Alternative on Matty's code (use/copy this Command1_Click() procedure over Matty's example code. It is not meant to be put in your Form, Reaper66613)
Note that this doesn't use any heavy string manipulations, nor splits or whatever (and it does close the file when a match is found :p)
Also note that the login.txt file is expected to be in the following format:
code:
guest|qwerty
login2|password2
login3|password3
login4|password4
code:
Private Sub Command1_Click()

    Dim strPath        As String
    Dim strText        As String
    Dim strMatchSearch As String
    Dim blnMatchFound  As Boolean

    strMatchSearch = txtUsername.Text & "|" & txtPassword.Text
    blnMatchFound = False

    strPath = App.Path
    If Right(strPath, 1) <> "\" Then strPath = strPath & "\"

    Open strPath & "text.txt" For Input As #1
        Do Until EOF(1) Or blnMatchFound
            Line Input #1, strText
            If strMatchSearch = strText Then blnMatchFound = True
        Loop
    Close #1

    If blnMatchFound Then
        MsgBox "Username/Pass match"
    Else
        MsgBox "Username/Pass not found"
    End If

End Sub


Help on MSDN Library (=official help files, which explain in full detail each command of VB) about:
Input #1
Line Input #1



For the 2 examples (one based on Matty's approach (project2), as listed above. The other the full working source of the VB example (project3)) see attached zip -------vv

.zip File Attachment: Example2-3.zip (4.04 KB)
This file has been downloaded 63 time(s).

This post was edited on 09-14-2005 at 07:51 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-14-2005 06:33 AM
Profile PM Find Quote Report
Reaper
Veteran Member
*****

Avatar

Posts: 1393
Reputation: 23
35 / Male / Flag
Joined: Jun 2004
O.P. RE: VB Help
omg cookie :D

thanks, it finally works :D

cheers to everyone else who posted (Y)
09-14-2005 02:58 PM
Profile E-Mail PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On