Yeah, the
Input way of taking a password works fairly good.
However, I myself prefer the good old way where the password inputed on the screen does not show up as the "real" word, but instead as ***** or something similiar.
There is a rather easy way of doing this in DBPro / DBClassic as well.
However, unlike the
Input way, it doesn't support deletion of previously entered characters (of course that could be implemented quite easily too by storing every single entered character in an array or similiar, but that you'll have to do yourself
)
My code for doing this is as follows:
Rem The RealPassword string repressents the correct password wich should be entered. (Edit this to whatever you wish).
RealPassword$="pass"
Rem Here we simply output a small message to ask the user for the password
Set cursor 0,0
Printc "Input password: "
Rem Here we make a simple loop to store the currently pressed key to the Password string
Rem and to output an asterix (*) instead of the actually entered character.
Rem When the returnkey is pressed, the loop ends and we go to the section wich checks whether
Rem the entered password is the same as the set RealPassword or not.
Repeat
If inkey$()>""
Password$=Password$+inkey$()
Printc "*"
Rem When a key is pressed, we wait a slight moment to prevent that the key is accidentally
Rem entered to many times.
Wait 250
Endif
Until returnkey()=1
Rem If the entered password equals the set password, we output "Correct password"
If Password$=RealPassword$ then center text screen width()/2,screen height()/2,"Correct password supplied!"
Rem Should the password be incorrect, we instead output "Incorrect password"
If Password$<RealPassword$ or Password$>RealPassword$ then center text screen width()/2,screen height()/2,"Invalid password supplied."
Rem Finally, we prompt the user for a keypress to terminate the program, after a slight
Rem moment of waiting (to prevent the accidental event that the program ends due to the
Rem returnkey from the inputting of the password earlier does not count as the 'any-key').
Wait 1000
Center text screen width()/2,screen height()-20,"(Press any key to exit)"
Suspend for key
End
So now, all you have to do is to edit that to suit your needs
Hope it comes in handy. ^^
Det är väl så