Board Logo
« password program bugfixed »

Welcome Guest. Please Login or Register.
Sep 26th, 2017, 07:34am


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: password program bugfixed  (Read 288 times)
zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 247
xx password program bugfixed
« Thread started on: Apr 3rd, 2017, 04:44am »

hi,
here is the modifed form of password program by laz
Code:
        pwd$="ok"
        nomainwin
        WindowWidth = 285 : WindowHeight= 130
        'center the window
        UpperLeftX = (DisplayWidth-WindowWidth)/2
        UpperLeftY = (DisplayHeight-WindowHeight)/2
        'graphicbox is used to capture key input
        graphicbox #pass.gb, 0,0,0,0
        textbox #pass.tb, 1,20,275,25
        'ok button optional
        button #pass.default, "Ok", [ok],UL 100,60,70,25
        open "Enter Password" for window as #pass
        print #pass, "trapclose [quitpass]"
        print #pass, "font courier_new 10 bold"
        print #pass.gb, "setfocus"
        print #pass.tb, "password"
        print #pass.gb, "when characterInput [pwd]"
        c=0:p$="":flg=0
        goto[denytb]
        wait
        [pwd]
        timer 0
        if flg=1 goto [pwd1]
        #pass.gb,"setfocus"
        k=asc(mid$(Inkey$,len(Inkey$),1))
        print k
        if k=13 then goto[end]
        if k<>8 and k<>13 then c=c+1:p$=p$+chr$(k)
        if k=8 and flg=0 and c>0 then timer 0:c=c-1:p$=left$(p$,c):flg=1
        m$=""
      for i=1 to c
            m$=m$+"*"
      next
        #pass.tb,m$:#pass.gb,"setfocus":goto[denytb]
        wait
        [pwd1]
        timer 0:#pass.gb,"setfocus"
        flg=0
        goto[denytb]
        [denytb]
        timer 500,[t]:#pass.gb,"setfocus"
        wait
        [t]
        timer 0:#pass.gb,"setfocus"
        goto[denytb]
        [ok]
        [end]
      if p$=pwd$ then
            note$="you are logged in"
      else
            note$="wrong password"
      end if
        notice note$
       [quitpass]
        close#pass
        end

 


here is the original program by laz shipped with JB
Code:
'This program is an example contributed by a Liberty BASIC community member.
'PASSWORD EXAMPLE WITH A MASK
'by laz on April 1, 2002

'password protect your programs with this simple password screen
'the password is masked with the asterisk you can change the mask
'to what ever you want. You can also use the backspace key to delete
'a charcter. You can use the enter key to press the Ok button after
' you enter the password
'
'you can remove the ok button and put all the timers to 10
'"timer 10, [t]" the just use the enter key to enter password
'
'the password in this example is "ok"
nomainwin
enter$ = chr$(_VK_RETURN) : backspace$ = chr$(_VK_BACK)
bs = 2 'for some reason when you press the
'backspace key it shows up twice and
'deletes two charcters. This is used
'as a counter so the backspace only
'deletes one charcter at a time
'** if anyone knows how to fix this please
'** post it to the group. Thanks

WindowWidth = 285 : WindowHeight= 130
'center the window
UpperLeftX = (DisplayWidth-WindowWidth)/2
UpperLeftY = (DisplayHeight-WindowHeight)/2

'graphicbox is used to capture key input
graphicbox #pass.gb, 0,0,0,0
textbox #pass.tb, 1,20,275,25
'ok button optional
button #pass.default, "Ok", [ok],UL 100,60,70,25
open "Enter Password" for window as #pass
print #pass, "trapclose [quitpass]"
print #pass, "font courier_new 10 bold"
print #pass.gb, "setfocus"
print #pass.gb, "when characterInput [letter]"
timer 400, [t]
wait

[t]
'if enter = 1 the enter key was pressed
if enter = 1 then timer 0 : goto [ok]
print #pass.gb, "setfocus"
wait

[letter]
timer 0
key$ = Inkey$ : key$ = left$(Inkey$, 2) : vkey$ = right$(key$,1)
if vkey$ <> enter$ and vkey$ <> backspace$ then
b$ = b$ + key$ : b = len(b$) : fill$ = ""
for x = 1 to b:fill$ = fill$ + "*" : next x 'fill mask with "*"
print #pass.tb, fill$ : print #pass.gb, "setfocus"
end if
if vkey$ = enter$ then enter = 1
if vkey$ = backspace$ and bs = 2 then
b = len(b$) : b=b-1 : b$ = left$(b$,b) : fill$ = ""
for x = 1 to b : fill$ = fill$ + "*" : next x 'fill mask with "*"
print #pass.tb, fill$ : print #pass.gb, "setfocus"
bs = bs +1: if bs = 3 then bs = 1 else if bs = 1 then bs = 2
end if : timer 400, [t]
wait

[quitpass]
timer 0
close #pass
end

[ok]
timer 0
if b$ = "ok" then 'password is "ok"
'do events for correct password
notice " " + chr$(13) + "Correct password" : print #pass.tb, ""
print #pass.gb, "setfocus" : b$ = ""
enter = 0 'leave timer off if opening a new window "timer 0"
timer 400, [t]
else
'do events for wrong password
notice " " + chr$(13) + "Wrong Password!" : print #pass.tb, ""
print #pass.gb, "setfocus" : b$ = "" : enter = 0 : timer 400, [t]
end if
wait

 
« Last Edit: Apr 3rd, 2017, 04:53am by zzz000abc » User IP Logged

zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 247
xx Re: password program bugfixed
« Reply #1 on: Apr 5th, 2017, 08:55am »

Two important problems has laz overcame very cleverly.

the first being to access key press , for this he defined a graphic box of zero dimensions.
the next problem is to avoid control shift to text box, for this he has used a timer.
User IP Logged

Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3089
xx Re: password program bugfixed
« Reply #2 on: Apr 5th, 2017, 10:22am »

Sadly its all based on a misunderstanding of how to read the keyboard. It was also penned in 2002 and we have all learned a little more.

Essentially you ignore the two character Inkey$ responses and only act on single character responses. The two character responses are telling you about control key input the single character responses are simply telling you about the key that was pressed, ONCE only.


Code:
nomainwin
e$ = chr$(_VK_RETURN)
b$ = chr$(_VK_BACK)
p$="abc123def"


WindowWidth = 300 : WindowHeight= 130
UpperLeftX = (DisplayWidth-WindowWidth)/2
UpperLeftY = (DisplayHeight-WindowHeight)/2

'graphicbox is used to capture key input
graphicbox #pass.gb, 0,0,0,0
textbox #pass.tb, 1,20,275,25
'allows user to press enter to complete entry
button #pass.default, "Ok", [check],UL 100,60,70,25
open "Enter Password" for window as #pass
#pass "trapclose [quit]"


#pass.gb "when characterInput [letter]"
#pass.gb "setfocus"
wait


[letter]

k$=Inkey$
select case

    case k$=e$
        goto [check]

    case k$=b$
        pw$=left$(pw$,len(pw$)-1)
        pb$=left$(pb$,len(pb$)-1)

    case else
        if asc(k$)>=33 and asc(k$)<=126 then
            pw$=pw$+k$ 
            pb$=pb$+"*"
        end if

end select
#pass.tb pb$


wait

[check]
if pw$=p$ then
    notice "Password Correct"
    close #pass
    end
else
    #pass.tb "Invalid Password"
    pw$=""
    pb$=""
end if
wait

[quit]
close #pass
end

 
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1157
xx Re: password program bugfixed
« Reply #3 on: Apr 5th, 2017, 11:51am »

And you don't need a Window to access a keypress!

example Reply #5 March 14
http://justbasic.conforums.com/index.cgi?board=shared&action=display&num=1489395260

A password was masked and code responded to enter or backspace keypress, all in mainwin!



« Last Edit: Apr 5th, 2017, 11:59am by bplus » User IP Logged

B+
Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3089
xx Re: password program bugfixed
« Reply #4 on: Apr 5th, 2017, 2:04pm »

You are using a window, mainwin, it's just a special kind of window. You can read the keyboard directly and without any window in Liberty BASIC via an api call to read the keyboard buffer. But most keyboard input is best handled with a window that gives instant user feedback.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls