Board Logo
« to check userid and password »

Welcome Guest. Please Login or Register.
Aug 17th, 2017, 06:23am


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: to check userid and password  (Read 296 times)
zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 245
xx to check userid and password
« Thread started on: Mar 13th, 2017, 03:54am »

Hi,
here is a program to check UserId and PassWord in Main Window :
Code:
 l$="apple,red9;mangO,yell0w;gPea,rGb000a00"
        'username,passwrd;
        n=3
        print pwd$(l$,n)
      function pwd$(d$,d)
            [user]
            input"enter user name : ";a$
          for i=1 to d
                if word$(word$(d$,i,";"),1,",")=a$ then exit for
          next
            if i=d+1 then print "user not found ":goto[user]
            [pwd]
            print "enter password : ";
            c$="":pw$=""
          while c$<>chr$(13)
                c$=input$()
                if c$<>chr$(13) then print "*"; :pw$=pw$+c$
          wend
            print
          if pw$=word$(word$(d$,i,";"),2,",") then
                print "you are logged in"
          else
                print "sorry wrong password":goto [pwd]
          end if
      end function

 
« Last Edit: Mar 13th, 2017, 04:08am by zzz000abc » User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1132
xx Re: to check userid and password
« Reply #1 on: Mar 13th, 2017, 11:53am »

Hi zzz000abc,

This may just be my way of coding but you have 2 obvious places to use a loop structure instead of goto. But that may be only opinion...

What is seriously wrong is that you don't offer any exits. Maybe you can allow only so many tries to get "user" right or password right and then end program if user is obviously not authorized and just guessing.
User IP Logged

B+
zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 245
xx Re: to check userid and password
« Reply #2 on: Mar 13th, 2017, 12:49pm »

on Mar 13th, 2017, 11:53am, bplus wrote:
Hi zzz000abc,

This may just be my way of coding but you have 2 obvious places to use a loop structure instead of goto. But that may be only opinion...

What is seriously wrong is that you don't offer any exits. Maybe you can allow only so many tries to get "user" right or password right and then end program if user is obviously not authorized and just guessing.

Absolutely Bplus where you are.
If it is not JB I would have used loops only.
Limiting to fixed number of trials part can be easily extended.
Here is the modified version:
Code:
        l$="apple,red9;mango,yell0w;gpea,rgb000a00"
        'username,passwrd;
        n=3
        nt=5 'max number of trials allowed
        print pwd$(l$,n,nt)
       FUNCTION pwd$(d$,d,mnt)
            i=d+1
           WHILE i=(d+1)
                input"enter user name : ";a$
               FOR i=1 to d
                    if word$(word$(d$,i,";"),1,",")=a$ then exit for
               NEXT
                if i=d+1 then print "user not found "
           WEND
           WHILE k<>mnt
                print "enter password : ";
                c$="":pw$=""
               WHILE c$<>chr$(13)
                    c$=input$()
                    if c$<>chr$(13) then print "*"; :pw$=pw$+c$
               WEND
                print
               IF pw$=word$(word$(d$,i,";"),2,",") then
                    print "you are logged in":exit while
               ELSE
                    print "sorry wrong password":k=k+1
               END if
           WEND
            if k=mnt then print"maximum trials exceeded":print"quitting..."
            pwd$=""
       END function
 
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1132
xx Re: to check userid and password
« Reply #3 on: Mar 13th, 2017, 3:55pm »

I love to see the use of the auto indent, it makes things so much easier to read, specially loops. (Maybe it's because the goto's are gone.)

Yes, you have fixed a limit to number of times a password is tried, I think we need the same thing for user too. It would be good also if the user could just quit after a couple of tries and they realize they need to lookup their name and password.)

I don't think the number of tries need be passed to the function but just build into the function.

And since it is a function, it should pass "true" or 1 if passed and "false" or 0 if failed. (I myself would use this code as a sub and just end the whole program in the sub if the user fails to log in correctly. But this function could be used to grant access to only a certain sensitive area in code like employee salaries.)

Also, I forgot to mention in first reply that I enjoyed your double use of Word$ to sort "user, password;... " as you know I am a fan of "array" strings.
« Last Edit: Mar 13th, 2017, 4:00pm by bplus » User IP Logged

B+
zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 245
xx Re: to check userid and password
« Reply #4 on: Mar 14th, 2017, 11:56am »

on Mar 13th, 2017, 3:55pm, bplus wrote:
I love to see the use of the auto indent, it makes things so much easier to read, specially loops. (Maybe it's because the goto's are gone.)

Yes, you have fixed a limit to number of times a password is tried, I think we need the same thing for user too. It would be good also if the user could just quit after a couple of tries and they realize they need to lookup their name and password.)

I don't think the number of tries need be passed to the function but just build into the function.

And since it is a function, it should pass "true" or 1 if passed and "false" or 0 if failed. (I myself would use this code as a sub and just end the whole program in the sub if the user fails to log in correctly. But this function could be used to grant access to only a certain sensitive area in code like employee salaries.)

Also, I forgot to mention in first reply that I enjoyed your double use of Word$ to sort "user, password;... " as you know I am a fan of "array" strings.

Thank you B+ for your support.
I would like to disagree with you at one point that is I think a programmer
should be given more freedom while using the function though end user is restricted.After all the programmer has to decide how many trails his user can make depending on the context..So the number should be passed along the function.
This function can used at different places for example as user login in a game,for opening a personal file encrypted,or dairy or notes etc.
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1132
xx Re: to check userid and password
« Reply #5 on: Mar 14th, 2017, 12:33pm »

Yes! It is the programmer's decision, absolutely, and the number of trials should depend upon the circumstances, sure! I don't see the function being used multiple times in a program so the trial amount could be built into the function... eh! six of one, half dozen of another... it is up to programmer, indeed.

I did try coding this myself and discovered that backspace works! So less trials are needed because if a user miss-keys the password, they could fix it before they press enter.

Code:
'pass protect.txt for JB [B+=MGA] 2017-03-14
' mods to zzz000abdc, I am curious how my version would look

global userPass$
userPass$ = "apple red9 mangO yell0w gPea rGb000a00"

user$ = passed$()
if user$ <> "" then print user$;" logged in." else print "Log-in failed."

function passed$()  'passed returns the name of the user it passed otherwise ""
    out$ = "Three strikes and you're out."
    do
        input"Enter user name: ";user$
        userNum = wIn(userPass$, user$)
        if userNum = 0 then strikes = strikes + 1 : print "Not registered, strike ";strikes
        if strikes = 3 then print out$ : exit function
    loop until userNum
    pass$ = word$(userPass$, userNum + 1)
    do
        pwd$ = "" : notOK = 1
        print "Enter Password: ";
        while notOK
            c$ = input$()
            if c$ = chr$(13) then
                if pwd$ <> pass$ then
                    strikes = strikes + 1 : print " No, strike ";strikes
                    if strikes = 3 then print out$ : exit function else exit while
                else
                    notOK = 0 : print
                end if
            else
                if c$ = chr$(8) then  'backspace will work!
                    if len(pwd$) then pwd$ = left$(pwd$, len(pwd$)-1)
                else
                    pwd$ = pwd$;c$
                    print "*";
                end if
            end if
        wend
    loop until pwd$ = pass$
    passed$ = word$(userPass$, userNum)
end function

function wIn(s$, w$) 'first in s$ that matches w$ (no spaces in w$!)
    wIn = 0 : wc = wCnt(s$)
    for i = 1 to wc
        if w$ = word$(s$, i) then wIn = i : exit function
    next
end function

function wCnt(s$) 'of default space delimited string
    while word$(s$, wc + 1) <> "" : wc = wc + 1 : wend
    wCnt = wc
end function

 


Security is a pain. If you make logging in convenient to a legitimate user, you make it more easy for people you are trying to keep out with the security. It is a bit silly with interpreter files.
« Last Edit: Mar 14th, 2017, 12:53pm by bplus » User IP Logged

B+
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