I need help with a login form too

  • Thread starter Thread starter carr4895
  • Start date Start date
C

carr4895

Hello.
I was wondering if someone could help me too with a login form. Upon
startup, I have to display a password screen and it should accept a
user name and password. User name can be anything non-blank. If
there is no user name, an appropriate error message must be displayed.
All of the following passwords are valid IT160, VB2Manager, BackDoor.
No other password is valid. It must allow the user to enter the
password in any case. If an invalid password is enterd, i need to
display an appropriate message. If no password is entered or if the
password is incorrect after three tries, display a sorry message and
exit the program. I am using VB.Net and it is an MDI form. Ineed to
display the password screen then the splash screen and the the parent
form. Please help. I am so confused. Thanks
 
You forgot to include the e-mail address of your instructor... or will you
handle the part where you turn it in for a grade?

Is there any part of the lesson which you are not confused about? We could
build from there unless you just want the A+ and prefer to skip the coding
part of things?
 
Hard coding passwords is not a good idea but in the event that you are doing
this, the code snippet here will do as you requested.

Place this into your Login button click procedure and away you go.

I hope this is not for a homework assignment for a programming course.

Dim strUserName As String

Dim strPassword As String

Static intPwdCounter As Integer

If Not intPwdCounter = 2 Then

If Not txtUserName.Text = "" Then

strUserName = txtUserName.Text

strPassword = txtPwd.Text

If UCase(strPassword) = "IT160" Or UCase(strPassword) = "VB2MANAGER" Or
UCase(strPassword) = "BACKDOOR" Then

Dim mySplash As New frmSplash

mySplash.Show()

Me.Hide()

Else

intPwdCounter += 1

MessageBox.Show("Incorrect Password! You have " & 3 - intPwdCounter & "
tries left.", "Password error", MessageBoxButtons.OK, MessageBoxIcon.Error)

txtPwd.Focus()

Exit Sub

End If

Else

MessageBox.Show("Please enter a username to continue.", "Login Error",
MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)

txtUserName.Focus()

Exit Sub

End If

Else

MessageBox.Show("Access Denied!", "Incorrect Login", MessageBoxButtons.OK,
MessageBoxIcon.Error)

Application.Exit()

End If
 
Gerry,

* "Gerry O'Brien said:
If UCase(strPassword) = "IT160" Or UCase(strPassword) = "VB2MANAGER" Or
UCase(strPassword) = "BACKDOOR" Then

I prefer (untested):

\\\
Select Case UCase(strPassword)
Case "IT160", "VB2MANAGER", "BACKDOOR"
...
Case Else
...
End Select
///

:-)
 
I prefer an array of strings just in case the professor asks for a 4th, 5th
or 6th password.
 
The clue (and other students take note) is that the specs are too exact,
right down to the passwords no less... so that would be uhhh the three he
decided to use, the three the CEO of the company he works for wanted or let
me guess... exactly what it says on the photocopied homework assignment?

If somebody posted an example with "PASSWORD1" there would be translation
work to be done and the huge possibility of it being handed in verbatim
yielding only a C+ for effort.
 
Hi Tom,
I prefer an array of strings just in case the professor asks for a 4th, 5th
or 6th password.

I would type almost this when I saw your message

Greath post about the lessons.

:-)

Cor
 
Tom,

* "Tom Leylan said:
I prefer an array of strings just in case the professor asks for a 4th, 5th
or 6th password.

:-)))

That's what I prefer too. I only wanted to show an alternative way to
write the code.
 
You guys are nasty...
I wouldn't want to have pigtails if you fellas were sitting behind
me...
I'd have to run home crying every day!

;)

If you decide to sit your MCP Carr, you might also like to check out
the BigFoot, "uh-hem", exam guides, "uh-hem".

hth
Richard
 
Better yet, let's use a collection of some sort like a hash table so we can
better manipulate them.

--
Gerry O'Brien
Visual Developer .NET MVP



Tom Leylan said:
I prefer an array of strings just in case the professor asks for a 4th, 5th
or 6th password.
 
Well. I am so sorry. I was just having trouble with the password
part of it. I thought you people could help me. I didn't mean to ask
for the whole thing. I am not a guy either so there. Thanks for
helping and I am sorry about the whole thing.
 
I don't know if you're still following along so I'll post it for your and/or
for others who may run across it...

It's my opinion of course but nobody here doesn't want to help. Similarly
nobody really wants to do you homework for you. Learning things you don't
know (after all) is the reason you are being asked to do the homework.
Girl, guy or somewhere in between we'd like the grade just as much as you
but we won't get it you will for all the work that somebody here puts into
your homework assignment.

As an alternative you might try posting what you've done so far. Then
somebody is bound to suggest an alternative or post a few lines of code to
get you past a tough spot. As you will (make that "should") notice you
didn't post the few lines of code that you were stuck on, you posted your
assignment with nary a line of code in sight.

Want a suggestion? Stick around and try to answer other people's questions.
That way you learn new stuff and you help others. It also gives you some
insight into the kinds of problems people run into and the type of things
you will be expected to know if you ever decide to get into software
development professionally.

Tom
 
I just needed help. I am so sorry for asking and for putting the
whole thing in. I am usually good at this kind of stuff but the
password part was hard for me. That is what i was having trouble
with. So don't critize mem. I am a good person. And I am not a guy
either. I was having trouble with cut, copy, and paste too but I am
not going to ask for any help. I was also going to have you look at
my slot machine game because i thought it would be cool for you people
to see it, but not anymore. Here is what I had before I even posted
the question.
Thanks
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
Dim strCapPass As String
'This line makes sure a User Name is entered.
'If not, it displays a message and exits the procedure.
If txtUserName.Text = "" Then
Unload.Me()
Else
MessageBox.Show("Must Enter User Name!", "Login")
txtUserName.Focus()
End If
'This line changes this text to capital letters
strCapPass = UCase(txtPassword.Text)
'This select statement checks the password
Select Case strCapPass
Case "IT160"
Unload(Me)
Case "VB2MANAGER"
Unload(Me)
Case "BACKDOOR"
Unload(Me)
Case Else
'Count how many times there is an invalid password
mintInvalPass = mintInvalPass + 1
'if there is less than three display the message
If mintInvalPass < 3 Then
MessageBox.Show("Invalid Password, try again!",
"Login")
'This line set the cursor in the txtPassword
textbox
txtPassword.Focus()
Else
'if there is more than three display sorry message
MessageBox.Show("Sorry, You Only get Three Trys!",
"Login")
End
End If
End Select
End Sub
I just had trouble converting it to VB.NET. Oh well.
Bye.
Then unload me part was confusing me.
 
There is probably little reason to continue the conversation but I'll take
one more stab at it.
I am a good person.
Nobody posted "you're a bad person."
And I am not a guy either.
Nobody suggested that you were and nobody cares if you are or aren't.
I was having trouble with cut, copy, and paste too but I am
not going to ask for any help.

That's your choice... I surely don't understand your decision but it is your
decision to make.
I was also going to have you look at my slot machine game because
i thought it would be cool for you people to see it, but not anymore.

Trust me we can write a slot machine program also. If not individually
certainly as a group :-)
Here is what I had before I even posted

You should have considered posting your code earlier then we could have made
suggestions for improvement. Please note (you seem intent on ignoring this)
you simply posted the "specs" which clearly was a homework assignment.
Personally I would give you a C as the code probably works. It is far from
elegant but you have to start somewhere.

Best of luck to you... the offer for you to post "answers" as a way to learn
remains open BTW.
 
Carr, you need to understand a couple of things.

1) We do not care about what sex you are. In the world of IT, guys or gals
are just as equally talented and sex make no difference to anyone here.

2) There are so many course out there now at high schools and secondary
educational institutions that teach VB .NET as the language of choice. I
personally teach at one of those secondary schools myself. The number of
people asking for help, in the exact same manner as you did, 9 out of 10
times, are looking for homework help.

3) Everyone in this group is here to help, not chastise or belittle you. We
all have questions from time to time as well and you will see us post asking
for help too. Nobody is perfect and nobody knows it all.

4) Don't let a bad experience prevent you from learning more. One of the
biggest beefs I have about newsgroup postings or anything in this style of
communication is the fact that feelings and emotions are so hard to convey
correctly. Some people seem harsh but that is just their way.

Continue to post any questions you like. We will do our best to answer what
we can.
 
Hi Carr4895,

A lot of philosophic words, but with that you can not buy bread.

I look what you did and take your approach, it is not the best, but that is
not importang when you start.
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
Dim strCapPass As String
'This line makes sure a User Name is entered.
'If not, it displays a message and exits the procedure.
If txtUserName.Text = "" Then

Unload.Me() 'Delete this row unload is from VB6
Else 'delete this else and than it goes when you
MessageBox.Show("Must Enter User Name!", "Login")
txtUserName.Focus()

exit sub ' just as you wrote
End If
'This line changes this text to capital letters
strCapPass = UCase(txtPassword.Text)
'This select statement checks the password

This you got from Herfried I remembered me.
Case "IT160", "VB2MANAGER", "BACKDOOR"

'Here is something needed, because it is OK

'and than
exit sub
I deleted all those case rows
Case Else
'Count how many times there is an invalid password
mintInvalPass = mintInvalPass + 1
This row above you can changhe for
mintIntvalPass += 1 ' I asume you have made that mintIntvalPas somewhere
else
'if there is less than three display the message
If mintInvalPass < 3 Then
MessageBox.Show("Invalid Password, try again!",
"Login")
'This line set the cursor in the txtPassword
textbox
txtPassword.Focus()
Else
'if there is more than three display sorry message
MessageBox.Show("Sorry, You Only get Three Trys!",
"Login")
End
End If
End Select
End Sub

I myself would not use that messagebox show on a slot machine but use a
label for it looks much nicer. That you use that txtPasword.Focus I find
very nice.

I hope this helps,

Cor
 
No one cares that its homework help... We don't mind helping on homework
help.

Just state it... "Hey, I don't understand this part about VB.NET, its a
homework problem"

Hell, I would have never gotten through college if I didn't have the
newsgroups. =)
 
Thank you for understanding. I am trying to learn. Well I needed to
switch the code to VB.NET and I am having trouble with the Unload Me
part in my code. That is the part I am having trouhle switching to
VB.NET. I was looking for homework help. I don't mean to seem so
mean either. I was just upset. I don't understand it. I am just
totally stress out. Can someone help me?
If txtUserName.Text = "" Then
Select Case strCapPass

Carr
 
Back
Top