VB.net help(easy amateur difficulty)

Pr3d4t0r

New member
Ok im not sure if this is the best section but whatever,

I have an assignment to complete fro college and im doing programming, which frankly is a pain in the arse especially with a retard of a teacher that doesnt teach us anything,

I need to write a program in vb studio 2010, i have most of it completed but i need to make a login form with a 3 attempts untill it locks out the user to login and the app needs to be restarted.

heres what i have so far,

any ,literally any help will be really appreciated, also try to make it look as if its done by a newb
tongue.png


Public Class Logon

Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click

Dim Username As String

Dim Password As String

Dim Form1 As Form

Dim Form2 As Form

Dim Count As Integer

Dim LoginTimes As Integer

LoginTimes = 0

Count = 0

Username = txtUsername.Text

Password = txtPassword.Text

Form1 = Me

Form2 = Calc_form

For LoginTimes = 0 To 2

If Username = "admin" = True And Password = "admin" = True Then

LoginTimes = 2

Form2.Show()

Me.Hide()

ElseIf Password = "admin" = False Then

MsgBox("Your password details are incorrect")

End If

If Username = "admin" = False Then

MsgBox("Your username details are incorrect")

End If

Next LoginTimes

End Sub

heres what it looks like:

Untitled-1.jpg
 
I do not have a lot of experiance programming in vb studio 2010. SO take this example and apply it to your program.

You need to wrap this into a While statement.

While loginTime <=3

If Username = "admin" = True And Password = "admin" = True Then

LoginTimes = 2

Form2.Show()

Me.Hide()

ElseIf Password = "admin" = False Then

MsgBox("Your password details are incorrect")

logintime ++

End If

if(loginTime==4)

MsgBox("You excedded the allowed login attempts.");

End If.
 
I do not have a lot of experiance programming in vb studio 2010. SO take this example and apply it to your program.

You need to wrap this into a While statement.

While loginTime <=3

If Username = "admin" = True And Password = "admin" = True Then

LoginTimes = 2

Form2.Show()

Me.Hide()

ElseIf Password = "admin" = False Then

MsgBox("Your password details are incorrect")

logintime ++

End If

if(loginTime==4)

MsgBox("You excedded the allowed login attempts.");

End If.

that pretty much same as my for loop but the problme is i need to be able to change the username and password each time, and not just loop all 4 times at once, thats the part i dont get the most.
 
Attempts= 0

If Username = txtUsername And Password = txtPassword Then

frmLoginSuccess.Show 'Shows the Login Success Form

frmLoginScreen.Hide 'Hides the Login Screen

Else

'A Message box that displays you have entered the wrong username and password

Attempts+=1

If Attempts< 3

MsgBox ("You have entered the wrong username and password")

Else

MsgBox ("Login attempts failed. Please contact Administration")

End If

End If
 
that pretty much same as my for loop but the problme is i need to be able to change the username and password each time, and not just loop all 4 times at once, thats the part i dont get the most.
I am not sure I understand your problem Do you want the Username and Password feilds to be reset after each attemp?
 
Attempts= 0

If Username = txtUsername And Password = txtPassword Then

frmLoginSuccess.Show 'Shows the Login Success Form

frmLoginScreen.Hide 'Hides the Login Screen

Else

'A Message box that displays you have entered the wrong username and password

Attempts+=1

If Attempts< 3

MsgBox ("You have entered the wrong username and password")

Else

MsgBox ("Login attempts failed. Please contact Administration")

End If

End If

that almost worked, probably my fault lol, if i put the

If attempts >=4 then ....

it doesnt execute the if command

and if i put <=4 then it executes it after first go.

any ideas? lol sry but im really bad at this.

current code:

LoginTimes = 0

Count = 0

Attempts = 0

Username = txtUsername.Text

Password = txtPassword.Text

Form1 = Me

Form2 = Calc_form

If Username = "admin" = True And Password = "admin" = True Then

MsgBox("Welcome")

Form2.Show()

Me.Hide()

End If

If Password = "admin" = False Then

MsgBox("Your password details are incorrect")

Attempts += 1

End If

If Username = "admin" = False Then

MsgBox("Your username details are incorrect")

Attempts += 1

End If

If Attempts <= 4 Then

MsgBox("You excedded the allowed login attempts")

MsgBox("Goodbye")

Me.Hide()

End If

End Sub
 
I am not sure I understand your problem Do you want the Username and Password feilds to be reset after each attemp?

no, its basically a login form, you have 3 attempts to log in with correct details, if after 3 go's you dont know the username and pass then a msgbox will display and me.hide.
 
OMG I DID IT!!! IM A GENIUS
biggrin.png


ok so i realised that it doesnt execute it because the the value of attempts is reseted to 0 each go, so i wrote the Dim Attempts as integer = 0 in the first line of form, i think thats called global variable or something, anyways the value of attempts is not being reset anymore so it locks out after however many attempts.

so proud of myself :]

but couldn't have done it without you two, thanks alot, now bac to the boring part of coding *sigh, i need some coffee
coffee.gif
 
It seems to me that you are increasing the attempts counter 2 times for each unsuccessful login attempt. Try to use an Or condition.



If Password = "admin" = False Or Username = "admin" = False Then

MsgBox("Your username or password details are incorrect")

Attempts += 1

End If


If Attempts >= 4 Then

MsgBox("You excedded the allowed login attempts")

MsgBox("Goodbye")

Me.Hide()

End If
 
OMG I DID IT!!! IM A GENIUS
biggrin.png


ok so i realised that it doesnt execute it because the the value of attempts is reseted to 0 each go, so i wrote the Dim Attempts as integer = 0 in the first line of form, i think thats called global variable or something, anyways the value of attempts is not being reset anymore so it locks out after however many attempts.

so proud of myself :]

but couldn't have done it without you two, thanks alot, now bac to the boring part of coding *sigh, i need some coffee
coffee.gif
congrats on figuring it out. good luck in your class.
 
It seems to me that you are increasing the attempts counter 2 times for each unsuccessful login attempt. Try to use an Or condition.

If Password = "admin" = False Or Username = "admin" = False Then

MsgBox("Your username or password details are incorrect")

Attempts += 1

End If

If Attempts >= 4 Then

MsgBox("You excedded the allowed login attempts")

MsgBox("Goodbye")

Me.Hide()

End If

thats a good idea, as i said im totally new to vb etc. and i dont know any commands apart from the ones i originally used in first form atempt, and yes i knew that and i knew its slighltly confusing and not accurate but its okay for now.

tested it now, and yup works like a charm, thanks again
 
cool

i wrote one for you.....

main form:

Public Class Form1

Public LoggedIn As Boolean

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load

If Me.Created = True Then

login.ShowDialog()

If LoggedIn = True Then

'successful log in

Else

'failed to log in

Me.Close()

End If

Else

Exit Sub

End If

End Sub

End Class


Log In form:

Public Class login

Public Attempts As Integer

Public realUser, realPass As String

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

If TextBox1.Text = realUser And TextBox2.Text = realPass Then

Form1.LoggedIn = True

Me.Close()

Else

Attempts += 1

If Attempts < 3 Then

MsgBox(AcceptButton, MsgBoxStyle.Exclamation, "Error")

TextBox1.Text = ""

TextBox2.Text = ""

Else

MsgBox(AcceptButton, MsgBoxStyle.Exclamation, "Error")

Form1.LoggedIn = False

Me.Close()

End If

End If

End Sub

Private Sub login_Load(sender As Object, e As System.EventArgs) Handles Me.Load

Attempts = 0

realPass = "password"

realUser = "admin"

End Sub

End Class
 
Man, its only been a few months without programming for me and already I seem to have forgotten it all, I saw this thread and thougt "Hey, maybe I can help someone" but then I read and in like dafuq
 
Back
Top