Password Problem
-
I have a form which has a button called "Modify Intrest" and when you click it, it brings up a password box and asks for the password. What I wanted was if password was typed in wrong three times, a message to display and then when you click OK, the application to close. If you type the password in correctly, I want an intrest rate box to display and you have to type in a number and it is written to a file ir.txt Here is code I have:
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click If txtIntrest.Text = ("") Then MsgBox("Please Enter Intrest Rate", MsgBoxStyle.Exclamation) Exit Sub End If If Not txtIntrest.Text.Equals(myline) Then Static passnum As Integer Do Dim pass As String = InputBox("Enter the Password", "Enter Password", "", ) If pass = "Password" Then Dim intrest As String = InputBox("Enter The New Intrest", "Enter Intrest Rate", "", ) txtIntrest.Text = (intrest) Dim theFile As FileStream = File.Create("ir.txt") Dim writer As StreamWriter = New StreamWriter(theFile) writer.WriteLine(txtIntrest.Text) writer.Close() theFile.Close() Exit Sub Exit Do Else Loop Until passnum = 3 passnum = +1 End If MsgBox("You have had three attempts to input password, Program will now close for security reasons", MsgBoxStyle.Critical) Application.Exit() End If End Sub
I messed it up slightly and not sure how to fix it, any ideas?In the end we're all just the same
-
I have a form which has a button called "Modify Intrest" and when you click it, it brings up a password box and asks for the password. What I wanted was if password was typed in wrong three times, a message to display and then when you click OK, the application to close. If you type the password in correctly, I want an intrest rate box to display and you have to type in a number and it is written to a file ir.txt Here is code I have:
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click If txtIntrest.Text = ("") Then MsgBox("Please Enter Intrest Rate", MsgBoxStyle.Exclamation) Exit Sub End If If Not txtIntrest.Text.Equals(myline) Then Static passnum As Integer Do Dim pass As String = InputBox("Enter the Password", "Enter Password", "", ) If pass = "Password" Then Dim intrest As String = InputBox("Enter The New Intrest", "Enter Intrest Rate", "", ) txtIntrest.Text = (intrest) Dim theFile As FileStream = File.Create("ir.txt") Dim writer As StreamWriter = New StreamWriter(theFile) writer.WriteLine(txtIntrest.Text) writer.Close() theFile.Close() Exit Sub Exit Do Else Loop Until passnum = 3 passnum = +1 End If MsgBox("You have had three attempts to input password, Program will now close for security reasons", MsgBoxStyle.Critical) Application.Exit() End If End Sub
I messed it up slightly and not sure how to fix it, any ideas?In the end we're all just the same
Dave McCool wrote:
Loop Until passnum = 3 passnum = +1 End If
You need to show the password dialog again inside this loop and check if it is entered right. This code doesn't allow anyone to try again.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Dave McCool wrote:
Loop Until passnum = 3 passnum = +1 End If
You need to show the password dialog again inside this loop and check if it is entered right. This code doesn't allow anyone to try again.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Thanks, but I am not 100% sure how to do this. I took out the code so it looks like this:
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click If txtIntrest.Text = ("") Then MsgBox("Please Enter Intrest Rate", MsgBoxStyle.Exclamation) Exit Sub End If If Not txtIntrest.Text.Equals(myline) Then Dim pass As String = InputBox("Enter the Password", "Enter Password", "", ) If pass = "Password" Then Dim intrest As String = InputBox("Enter The New Intrest", "Enter Intrest Rate", "", ) txtIntrest.Text = (intrest) Dim theFile As FileStream = File.Create("ir.txt") Dim writer As StreamWriter = New StreamWriter(theFile) writer.WriteLine(txtIntrest.Text) writer.Close() theFile.Close() Exit Sub End If End If End Sub
So the password box just closes when the wrong password is input. I want the password box to keep displaying istead of closing and if you type password wrong three times, this code to execute:MsgBox("You have had three attempts to input password, Program will now close for security reasons", MsgBoxStyle.Critical) Application.Exit()
but I was told I could do this with a loop, but was not sure how I had code:Static passnum As Integer Do passnum = +1 Loop Until passnum = 3
but was not sure where to put it so it worked, any ideas?In the end we're all just the same