|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Password Changeim pretty new to the whole coding aspect of vb im in a bit of a prob im creating a simple database program,listing inventions of the victorian era-but thats niot important my biggest 2 problems are that when ive filled a text box,i cant get a scroll down bar,lit just keeps going across,without any scroll bar the other problem is that i cant get the user to change the password ive put a password in notepad,which will be overwritten by the new password,but it is not working too well at the mo my logon code is like this Private Sub cmdenter_Click() Static i As Integer Dim current As String Open App.Path & "\password.txt" For Input As #2 Line Input #2, current Close #2 If i < 3 Then If txtusername = "BHPSteacher" Then If txtpassword = current Then Unload Me Unload frmentryscreen frmchoosescreen.Show Else MsgBox "Incorrect Username/Password" i = i + 1 End If Else i = i + 1 End If Else i = i + 1 End If If i = 3 Then MsgBox "You have failed 3 times - You are unauthorised to access - Goodbye" Unload Me Unload frmentryscreen End If 'if password is the same as on notepad,if username is correct,allows access to next screen,3wrong prog ends End Sub and the password change is Private Sub cmdexit_Click() Unload Me 'closes the current form and takes you back to frmchoosescreen End Sub Private Sub cmdok_Click() Open App.Path & "\password.txt" For Input As #2 Line output #2, current Close #2 'all the above checks the current password in notepad If txtoldpassword = current Then 'if the input password is correct, the prog can continue If txtnewpassword = txtconfirmnewpassword Then 'if the 2 passwords,can continue Print #2, txtnewpassword Close #2 'replaces old password for new password in notepad MsgBox "Your password has been changed" Else MsgBox "incorrect password" End If End If End Sub i think that the problem is somewhere in the line input/output are, but i dont know what is wrong any help would be a great help humbly bowingin the face of superior knowledge hirostroud The reason is doesn't work is that you are opening the file for input and
then trying to write to it. But if you wanted an example of how not to do things, yours is great: Use FreeFile, don't hardcode file numbers Never never never ever store a password (especially in a file called "password.txt" d'oh!) - what you should do is put the password throug a routine called a hash. This gives a result, often a number, which you cannot derive the original string from. To check the password you have the hash result stored, and then you compare that with a hash of whatever the user entered. Probably better to store this in the registry - See "SaveSetting" and "GetSetting". Avoid putting any code in a form after "Unload Me", code executed after that *may* cause the form to be reloaded. Never assume App.Path has or doesn't have a trailing slash, you should always check. Some people will advise against using the defualt property. i.e. Use "txtusername.Text" instead of "txtusername" Sorry to be so critical but if these aren't pointed out you will never know. Best Regards Dave O. Show quoteHide quote "hirostroud" <twinfiresofdarkn***@hotmail.com> wrote in message news:1141985972.865263.176680@u72g2000cwu.googlegroups.com... > hey > im pretty new to the whole coding aspect of vb > im in a bit of a prob > im creating a simple database program,listing inventions of the > victorian era-but thats niot important > my biggest 2 problems are that when ive filled a text box,i cant get a > scroll down bar,lit just keeps going across,without any scroll bar > the other problem is that i cant get the user to change the password > ive put a password in notepad,which will be overwritten by the new > password,but it is not working too well at the mo > > my logon code is like this > > Private Sub cmdenter_Click() > Static i As Integer > Dim current As String > > Open App.Path & "\password.txt" For Input As #2 > Line Input #2, current > Close #2 > If i < 3 Then > If txtusername = "BHPSteacher" Then > If txtpassword = current Then > Unload Me > Unload frmentryscreen > frmchoosescreen.Show > Else > MsgBox "Incorrect Username/Password" > i = i + 1 > End If > Else > i = i + 1 > End If > Else > i = i + 1 > End If > If i = 3 Then > MsgBox "You have failed 3 times - You are unauthorised to access - > Goodbye" > Unload Me > Unload frmentryscreen > End If > 'if password is the same as on notepad,if username is correct,allows > access to next screen,3wrong prog ends > > End Sub > > and the password change is > > Private Sub cmdexit_Click() > Unload Me > 'closes the current form and takes you back to frmchoosescreen > End Sub > > Private Sub cmdok_Click() > Open App.Path & "\password.txt" For Input As #2 > Line output #2, current > Close #2 > 'all the above checks the current password in notepad > If txtoldpassword = current Then > 'if the input password is correct, the prog can continue > If txtnewpassword = txtconfirmnewpassword Then > 'if the 2 passwords,can continue > Print #2, txtnewpassword > Close #2 > 'replaces old password for new password in notepad > MsgBox "Your password has been changed" > Else > MsgBox "incorrect password" > End If > End If > End Sub > > i think that the problem is somewhere in the line input/output are, but > i dont know what is wrong > any help would be a great help > humbly bowingin the face of superior knowledge > hirostroud > About the lack of a scroll-bar on the text box -- you want the text box to
have the "multiline" property. - lr -- Show quoteHide quote"Dave" wrote: > The reason is doesn't work is that you are opening the file for input and > then trying to write to it. > > But if you wanted an example of how not to do things, yours is great: > Use FreeFile, don't hardcode file numbers > Never never never ever store a password (especially in a file called > "password.txt" d'oh!) - what you should do is put the password throug a > routine called a hash. This gives a result, often a number, which you cannot > derive the original string from. To check the password you have the hash > result stored, and then you compare that with a hash of whatever the user > entered. Probably better to store this in the registry - See "SaveSetting" > and "GetSetting". > Avoid putting any code in a form after "Unload Me", code executed after that > *may* cause the form to be reloaded. > Never assume App.Path has or doesn't have a trailing slash, you should > always check. > Some people will advise against using the defualt property. i.e. Use > "txtusername.Text" instead of "txtusername" > > Sorry to be so critical but if these aren't pointed out you will never know. > > Best Regards > Dave O. > > "hirostroud" <twinfiresofdarkn***@hotmail.com> wrote in message > news:1141985972.865263.176680@u72g2000cwu.googlegroups.com... > > hey > > im pretty new to the whole coding aspect of vb > > im in a bit of a prob > > im creating a simple database program,listing inventions of the > > victorian era-but thats niot important > > my biggest 2 problems are that when ive filled a text box,i cant get a > > scroll down bar,lit just keeps going across,without any scroll bar > > the other problem is that i cant get the user to change the password > > ive put a password in notepad,which will be overwritten by the new > > password,but it is not working too well at the mo > > > > my logon code is like this > > > > Private Sub cmdenter_Click() > > Static i As Integer > > Dim current As String > > > > Open App.Path & "\password.txt" For Input As #2 > > Line Input #2, current > > Close #2 > > If i < 3 Then > > If txtusername = "BHPSteacher" Then > > If txtpassword = current Then > > Unload Me > > Unload frmentryscreen > > frmchoosescreen.Show > > Else > > MsgBox "Incorrect Username/Password" > > i = i + 1 > > End If > > Else > > i = i + 1 > > End If > > Else > > i = i + 1 > > End If > > If i = 3 Then > > MsgBox "You have failed 3 times - You are unauthorised to access - > > Goodbye" > > Unload Me > > Unload frmentryscreen > > End If > > 'if password is the same as on notepad,if username is correct,allows > > access to next screen,3wrong prog ends > > > > End Sub > > > > and the password change is > > > > Private Sub cmdexit_Click() > > Unload Me > > 'closes the current form and takes you back to frmchoosescreen > > End Sub > > > > Private Sub cmdok_Click() > > Open App.Path & "\password.txt" For Input As #2 > > Line output #2, current > > Close #2 > > 'all the above checks the current password in notepad > > If txtoldpassword = current Then > > 'if the input password is correct, the prog can continue > > If txtnewpassword = txtconfirmnewpassword Then > > 'if the 2 passwords,can continue > > Print #2, txtnewpassword > > Close #2 > > 'replaces old password for new password in notepad > > MsgBox "Your password has been changed" > > Else > > MsgBox "incorrect password" > > End If > > End If > > End Sub > > > > i think that the problem is somewhere in the line input/output are, but > > i dont know what is wrong > > any help would be a great help > > humbly bowingin the face of superior knowledge > > hirostroud > > > > > "Dave" <nob***@nowhere.com> wrote: Here's a one-liner I wrote that will check for trailing slashes:> Never assume App.Path has or doesn't have a trailing slash, you should > always check. strFilePath = Replace(App.Path & "\", "\\", "\") & "YourTextFile.txt" Hi, Dave
Seeing we're criticising your nooby attempts, I might as well toss in my two cents worth. I notice you have repeated incrementing 'i' in **all** of the "if" statements Think about it Your code would be clearer (and more efficient ) written as follows If i < 3 Then If txtusername = "BHPSteacher" Then If txtpassword = current Then Unload Me Unload frmentryscreen frmchoosescreen.Show Else MsgBox "Incorrect Username/Password" End If End If End If i = i + 1 If i = 3 Then ... Argusy <snip>
how to convert string to date?
TransparentBlt and Autoredraw issues (refresh isnt solving it) Text to Speech VB6 writing to text files requires Close to commit Picturebox fit newbe question Code for stored procedures Call a DLL in C from VB Using VB to screen scrape a 3270 mainframe Error to create a package in VB6 Close a form |
|||||||||||||||||||||||