Author |
Topic: Simple Password Masking (Read 94 times) |
|
jaba
Junior Member
  
member is offline


Gender: 
Posts: 96
|
 |
Simple Password Masking
« Thread started on: Nov 6th, 2009, 2:41pm » |
|
A simple routine that masks the password as user enters it and then confirms it. Doesn't require a lot of code just to display an asterisk. Code:nomainwin
password$="secret"
WindowWidth=260
WindowHeight=160
statictext #1.st, "Enter user name and password", 30, 10, 200, 20
textbox #1.tb, 30, 35, 100, 25
textbox #1.tb2, 30, 65, 100, 25
button #1.ok, " Confirm ", [maskMe], UL, 135, 65
statictext #1.st2, "", 30, 100, 200, 25
statictext #1.st3, ">>", 18, 100, 11, 25
open "Password Test" for window as #1
#1 "trapclose [quit]"
#1.tb, "!setfocus";
#1.tb2, "!font symbol 6";
[askMe]
#1.tb2, ""
wait
[maskMe]
#1.tb2, "!setfocus"
#1.tb2, "!contents? pass$"
fl=len(pass$)
if right$(pass$, 2)=chr$(13) then
pass$=left$(pass$, fl)
end if
if pass$=password$ then
#1.st2, "Password confirmed"
else
#1.st2, "Incorrect. Enter new password" :goto [askMe]
end if
wait
[quit]
close #1
end
This may not be too secure, but it should work fine for games and simple programs requiring a password to continue.
|
|
Logged
|
|
|
|
cundo
ThreadRestoreGroup
  
member is offline


Gender: 
Posts: 887
|
 |
Re: Simple Password Masking
« Reply #1 on: Nov 7th, 2009, 2:59pm » |
|
This one uses a graphicbox to display random data Code:nomainwin
mypass$="secret"
ForegroundColor$ = "BLACK" : BackgroundColor$= "BUTTONFACE"
WindowWidth=380 : WindowHeight=130
textbox #1.tb1, 30, 35, 100, 25
'the graphicbox that displays the random symbols
graphicbox #1.gbx, 132, 35, 100, 25
TextboxColor$ = "BLACK"
' this hidden textbox is going to take the user input.
textbox #1.tb2, 30, -100, 100, 25
' a default button recieves input from the Enter Key
button #1.default, "Accept", [check], UL, 242, 35,100,25
open "The Password is ";CHR$(39);"secret";CHR$(39) for dialog_nf as #1
#1 "trapclose [quit]"
#1 "Font Courier_new 10"
#1.gbx "Font Courier_new 7 19 bold"
#1.gbx, "color red; backcolor white"
#1.gbx, "down ; fill white ; flush "
#1.tb1, "!setfocus"
#1.gbx, "when leftButtonDown [lbd]"
wait
[lbd]
#1.tb2 "!setFocus"
#1.tb1 "!contents? nameText$"
#1.gbx "fill white"
[simtb]
Timer 0
#1.tb2 "!contents? verify$"
ToDsp$ =""
For i = 1 To Len(verify$)
t$ = CHR$( int( rnd(0)*10 ) + 48)
ToDsp$ = ToDsp$;t$;" "
Next
#1.gbx "place 1 13"
#1.gbx "|";ToDsp$;space$(10)
#1.gbx "discard"
Timer 100, [simtb]
wait
[check]
#1.gbx "cls" : #1.tb2 ""
Timer 0
if verify$=mypass$ then
great = 1
goto [quit]
end if
#1.gbx "place 1 13;cls;fill white"
#1.gbx "|Wrong Pass!"
playwave "no_wave_here"
#1.tb1, "!setfocus"
wait
[quit]
if great then notice "YEAH!";CHR$(13);"The Password is correct!"
close #1
END
There is a problem, sometimes the textboxes do not accept input. ???
|
| « Last Edit: Nov 7th, 2009, 2:59pm by cundo » |
Logged
|
cundo aka MSlayer
|
|
|
Stefan Pendl
Administrator
    
member is offline

Let's talk JB ...

Gender: 
Posts: 2158
|
 |
Re: Simple Password Masking
« Reply #2 on: Nov 8th, 2009, 04:48am » |
|
on Nov 7th, 2009, 2:59pm, cundo wrote:This one uses a graphicbox to display random data
---snip
There is a problem, sometimes the textboxes do not accept input. |
|
Make sure to set the focus to the next control just before the WAIT command, else it can happen, that the control will loose focus, because you are accessing a different control from within your code.
|
|
Logged
|
Stefan
Any code I post can be used by others in their own projects, there is no need to ask for permission, just give credit if you like
Just BASIC 1.01, Windows Vista Home Premium SP2, AMD Turion X2 RM-70 2GHz, 4GB RAM
|
|
|
|