Thread View: comp.lang.basic.visual.misc
4 messages
4 total messages
Started by MikeG in Philly
Sat, 11 Mar 2000 00:00
HELP! I need a loop! Can't figure this...
Author: MikeG in Philly
Date: Sat, 11 Mar 2000 00:00
Date: Sat, 11 Mar 2000 00:00
59 lines
2370 bytes
2370 bytes
Hi Folks: the following code snippet is a loop for a password, and it works
fine as it is...but I need to give the user three tries before exiting the
sub and can't figure out the loop...can you help?
Here's the code...
Private Sub cmdOK_Click()
Dim strLName As String
Dim strPW1 As String
Dim strLevel As String
intCount = intCount + 1
Open "a:\password.dat" For Input As #1
Do While Not EOF(1)
Input #1, strLName, strPW1, strLevel
If LCase(Trim(strLName)) = LCase(Trim(txtUserName.Text)) And
LCase(Trim(strPW1)) = LCase(Trim(txtPassword.Text)) And
LCase(Trim(strLevel)) = 3 Then
frmMain.Show
Me.Hide
Close #1
Exit Sub
Else
If LCase(Trim(strLName)) = LCase(Trim(txtUserName.Text)) And
LCase(Trim(strPW1)) = LCase(Trim(txtPassword.Text)) And
LCase(Trim(strLevel)) = 2 Then
Me.Hide
frmMain.Show
frmMain.cmdAssign.Visible = False
frmTables.cmdOrders.Visible = False
frmTables.cmdOL.Visible = False
frmTables.cmdPurch.Visible = False
frmTables.cmdCR.Visible = False
Close #1
Exit Sub
Else
If LCase(Trim(strLName)) = LCase(Trim(txtUserName.Text)) And
LCase(Trim(strPW1)) = LCase(Trim(txtPassword.Text)) And
LCase(Trim(strLevel)) = 1 Then
Me.Hide
frmMain.cmdView.Visible = False
frmMain.Show
Close #1
Exit Sub
End If
End If
End If
Loop
Close #1
MsgBox "Sorry, wrong password."
End Sub
Re: HELP! I need a loop! Can't figure this...
Author: Joe "Nuke Me Xemu" Foster
Date: Sat, 11 Mar 2000 00:00
Date: Sat, 11 Mar 2000 00:00
115 lines
4201 bytes
4201 bytes
"MikeG in Philly" <PhilaPA@hotmail.com> wrote in message news:38cae00b@news3.enter.net...
> Hi Folks: the following code snippet is a loop for a password, and it works
> fine as it is...but I need to give the user three tries before exiting the
> sub and can't figure out the loop...can you help?
> Here's the code...
> Private Sub cmdOK_Click()
> Dim strLName As String
> Dim strPW1 As String
> Dim strLevel As String
> intCount = intCount + 1
Is intCount a global, form-level, or static variable, or what?
> Open "a:\password.dat" For Input As #1
> Do While Not EOF(1)
> Input #1, strLName, strPW1, strLevel
>
> If LCase(Trim(strLName)) = LCase(Trim(txtUserName.Text)) And
> LCase(Trim(strPW1)) = LCase(Trim(txtPassword.Text)) And
Why shouldn't the password be case sensitive? Check out StrComp in the help.
> LCase(Trim(strLevel)) = 3 Then
> frmMain.Show
> Me.Hide
> Close #1
> Exit Sub
>
> Else
Either use ElseIf or fix your indenting.
> If LCase(Trim(strLName)) = LCase(Trim(txtUserName.Text)) And
> LCase(Trim(strPW1)) = LCase(Trim(txtPassword.Text)) And
> LCase(Trim(strLevel)) = 2 Then
> Me.Hide
> frmMain.Show
> frmMain.cmdAssign.Visible = False
> frmTables.cmdOrders.Visible = False
> frmTables.cmdOL.Visible = False
> frmTables.cmdPurch.Visible = False
> frmTables.cmdCR.Visible = False
> Close #1
> Exit Sub
> Else
> If LCase(Trim(strLName)) = LCase(Trim(txtUserName.Text)) And
> LCase(Trim(strPW1)) = LCase(Trim(txtPassword.Text)) And
> LCase(Trim(strLevel)) = 1 Then
> Me.Hide
> frmMain.cmdView.Visible = False
> frmMain.Show
> Close #1
> Exit Sub
> End If
> End If
> End If
> Loop
> Close #1
> MsgBox "Sorry, wrong password."
> End Sub
Here's how I might do it, based on what you've shown us:
Open "a:\password.dat" For Input As #1
Do While intCount > 0 And Not EOF(1)
Input #1, strLName, strPW1, strLevel
If StrComp(strLName, txtUserName.Text, 0) <> 0 Then
' nope
ElseIf StrComp(strPW1, txtPassword.Text, 0) <> 0 Then
' sorry
ElseIf strLevel = 3 Then
intCount = 0
ElseIf strLevel = 2 Then
intCount = 0
frmMain.cmdAssign.Visible = False
frmTables.cmdOrders.Visible = False
frmTables.cmdOL.Visible = False
frmTables.cmdPurch.Visible = False
frmTables.cmdCR.Visible = False
ElseIf strLevel = 1 Then
intCount = 0
frmMain.cmdView.Visible = False
End If
Loop
Close #1
If IntCount = 0 Then
frmMain.Show
Me.Hide
ElseIf IntCount < 3 Then
txtPassword.Text = vbNullString
txtPassword.SetFocus
MsgBox "Sorry, wrong password."
ElseIf IntCount = 3 Then
MsgBox "Game over, man! Game over!"
Unload Me
End If
I'd really want to use at least a one-way hash for that password file.
--
Joe Foster <mailto:jfoster@ricochet.net> Space Cooties! <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above They're coming to
because my cats have apparently learned to type. take me away, ha ha!
Re: HELP! I need a loop! Can't figure this...
Author: MikeG in Philly
Date: Sun, 12 Mar 2000 00:00
Date: Sun, 12 Mar 2000 00:00
133 lines
4925 bytes
4925 bytes
Hi Joe! Many thanks for taking the time to reply to me, but I just tried this code and it doesn't work...it allows full access to the main form even with a garbage password. I need something for class tomorrow, The idea is to allow a user 3 tries to login and then exit the sub. Hope someone can help...I have spent hours on this with no success...Mike -------------------------------------------- "Joe "Nuke Me Xemu" Foster" <joe@bftsi0.UUCP> wrote in message news:scm0r3mea5n96@corp.supernews.com... > "MikeG in Philly" <PhilaPA@hotmail.com> wrote in message news:38cae00b@news3.enter.net... > > > Hi Folks: the following code snippet is a loop for a password, and it works > > fine as it is...but I need to give the user three tries before exiting the > > sub and can't figure out the loop...can you help? > > > Here's the code... > > > > Private Sub cmdOK_Click() > > > Dim strLName As String > > Dim strPW1 As String > > Dim strLevel As String > > intCount = intCount + 1 > > Is intCount a global, form-level, or static variable, or what? > > > Open "a:\password.dat" For Input As #1 > > Do While Not EOF(1) > > Input #1, strLName, strPW1, strLevel > > > > If LCase(Trim(strLName)) = LCase(Trim(txtUserName.Text)) And > > LCase(Trim(strPW1)) = LCase(Trim(txtPassword.Text)) And > > Why shouldn't the password be case sensitive? Check out StrComp in the help. > > > LCase(Trim(strLevel)) = 3 Then > > frmMain.Show > > Me.Hide > > Close #1 > > Exit Sub > > > > Else > > Either use ElseIf or fix your indenting. > > > If LCase(Trim(strLName)) = LCase(Trim(txtUserName.Text)) And > > LCase(Trim(strPW1)) = LCase(Trim(txtPassword.Text)) And > > LCase(Trim(strLevel)) = 2 Then > > Me.Hide > > frmMain.Show > > frmMain.cmdAssign.Visible = False > > frmTables.cmdOrders.Visible = False > > frmTables.cmdOL.Visible = False > > frmTables.cmdPurch.Visible = False > > frmTables.cmdCR.Visible = False > > Close #1 > > Exit Sub > > Else > > If LCase(Trim(strLName)) = LCase(Trim(txtUserName.Text)) And > > LCase(Trim(strPW1)) = LCase(Trim(txtPassword.Text)) And > > LCase(Trim(strLevel)) = 1 Then > > Me.Hide > > frmMain.cmdView.Visible = False > > frmMain.Show > > Close #1 > > Exit Sub > > > End If > > End If > > End If > > > Loop > > > > Close #1 > > MsgBox "Sorry, wrong password." > > > End Sub > > Here's how I might do it, based on what you've shown us: > > Open "a:\password.dat" For Input As #1 > Do While intCount > 0 And Not EOF(1) > Input #1, strLName, strPW1, strLevel > > If StrComp(strLName, txtUserName.Text, 0) <> 0 Then > ' nope > ElseIf StrComp(strPW1, txtPassword.Text, 0) <> 0 Then > ' sorry > ElseIf strLevel = 3 Then > intCount = 0 > ElseIf strLevel = 2 Then > intCount = 0 > frmMain.cmdAssign.Visible = False > frmTables.cmdOrders.Visible = False > frmTables.cmdOL.Visible = False > frmTables.cmdPurch.Visible = False > frmTables.cmdCR.Visible = False > ElseIf strLevel = 1 Then > intCount = 0 > frmMain.cmdView.Visible = False > End If > Loop > Close #1 > > If IntCount = 0 Then > frmMain.Show > Me.Hide > ElseIf IntCount < 3 Then > txtPassword.Text = vbNullString > txtPassword.SetFocus > MsgBox "Sorry, wrong password." > ElseIf IntCount = 3 Then > MsgBox "Game over, man! Game over!" > Unload Me > End If > > I'd really want to use at least a one-way hash for that password file. > > -- > Joe Foster <mailto:jfoster@ricochet.net> Space Cooties! <http://www.xenu.net/> > WARNING: I cannot be held responsible for the above They're coming to > because my cats have apparently learned to type. take me away, ha ha! > >
Re: HELP! I need a loop! Can't figure this...
Author: Joe "Nuke Me Xemu" Foster
Date: Sun, 12 Mar 2000 00:00
Date: Sun, 12 Mar 2000 00:00
14 lines
1606 bytes
1606 bytes
"MikeG in Philly" <PhilaPA@hotmail.com> wrote in message news:38cb7cf5@news3.enter.net... > Hi Joe! Many thanks for taking the time to reply to me, but I just tried > this code and it doesn't work...it allows full access to the main form even > with a garbage password. I need something for class tomorrow, The idea is to > allow a user 3 tries to login and then exit the sub. Hope someone can > help...I have spent hours on this with no success...Mike What did I do, leave out the intCount = intCount + 1 bit? -- Joe Foster <mailto:jfoster@ricochet.net> Space Cooties! <http://www.xenu.net/> WARNING: I cannot be held responsible for the above They're coming to because my cats have apparently learned to type. take me away, ha ha!
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads