Link to home
Start Free TrialLog in
Avatar of kevsh
kevsh

asked on

Passwording a program

How do I code a VB program to ask for a login and password?  It should be the first form that loads when I execute my program.

Points will go up if you can provide code for this.
ASKER CERTIFIED SOLUTION
Avatar of Dr. Kamal Mehdi
Dr. Kamal Mehdi
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, there is a mistake in the code. It should be:
MyLoginName = "lllll"
MyPassword = "ppppp"

If Text1 = MyLoginName and Text2 = MyPassword Then
   Form1.Show   'Your first form
Else
   Msgbox "Incorrect Login name or password"
   End
End If
Also, if the login is correct, you must unload the login form by inserting the following line after the Form1.Show line:

Unload Me
Avatar of v_iyengar
v_iyengar

Have a module
in the module
sub main
  frmLogin.show
end





have  2 textbox and a button


on button click
check the value of the text box with the value stored in a
database
the password must not be hard coded

the password must be in database

you should also allow to change the password
if you hard code you can not give this feature



After checking if the password is correct the call the first form
of your Application
other wise unload the login form
Don't forget to set the password box's "Password Character(?)" to something other than "". For standard purposes, set it to "*".
Or just go to insert form and choose a login form, all code provided for you!
AS suggested, the code from Random Task is there for you...it's only short coming is the same as that of your proposed answer...you can't change the passwork because it is hard coded...one should have the ability to change passwords and as well it should eat the password if tried more than x times and failed...to prevent too many chances of breaking your password.
You need to write the password to a file and then open the file and compare your text box entry to the file. On change you open the file for output and just replace the old password with the new.For eating the password you just use a counter for each time the enter button was pressed and when it reaches your max you lock the textboxes and msg the user that the program is locked and can only be unlocked by administrator. Of course, you now have another page that the administrator only can call and it has the ability to overwite the file and unlock the text boxes etc.

That should about do it...
good luck...