
-----------------------------------
Darkshining
Mon Sep 19, 2005 8:52 pm

Password and Usernames loggin
-----------------------------------
Hi, i am a first time poster on this forum, i searched up the forum for this but none of them actually explained what i want to do:
I've wrote a program that you can set a password and it gives you 4 attemps before locking your account down. 
i want to achieve:
1. make password into *s
2. make a database that can save people's usernames and bring them up on command with matching passwords

var VAR_PWD : string
var VAR_PASSWD : string :="88888" %User defined Password
var d : int :=4 %how many times do you want the user to attempt?
for i: 1 .. d
     put "Please enter your password."
     get VAR_PWD
if   VAR_PWD not= VAR_PASSWD then
     put "Wrong Password, ", i, " Attempt."
if   i = d then put "Your Account is locked for safety purposes."
end if
else 
     put "Thank you for logging in."
     exit 
end if     
     end for

-----------------------------------
Tony
Mon Sep 19, 2005 9:18 pm


-----------------------------------
for *s, View.Set("noecho") and use getch char in a loop.

for a "database", just read/write to file.

-----------------------------------
Darkshining
Mon Sep 19, 2005 9:30 pm


-----------------------------------
i started learning turing a week ago, so your answer doesn't really ring a bell to me.
can you impliment the *s in my program so i can see what what mean?
i know getch is getcharacter, but it only works with string (1), if i want the user to define a password, then i wouldn't know how many of them to use.

-----------------------------------
Tony
Mon Sep 19, 2005 9:36 pm


-----------------------------------
that's why I've said to use getch inside a loop. Get one character at a time until the user is done (return key?)


View.Set("noecho")
var c:string(1)
loop
  getch c
  put "*"..
end loop

try to figure out what you can do with that c character :wink:

-----------------------------------
Darkshining
Tue Sep 20, 2005 10:32 am


-----------------------------------
that is the code, it uses ****, but the enter key does not work now, is there a way around it?
var VAR_PWD : string := "55555"
var VAR_Pass : string
var d : int :=4
for i : 1 .. d
put "Please enter your password." 
View.Set("noecho") 
var c:string(1) 
loop 
  getch (c) 
  put "*".. 
end loop
get VAR_Pass
if VAR_Pass not= VAR_PWD then
put "Wrong password, ", i, " attemps."
if i = d then
put "Your account has been locked down for safety purposes."
end if
else put "Thank you for loggin in."
exit
end if
end for[/code]

-----------------------------------
TokenHerbz
Tue Sep 20, 2005 1:43 pm


-----------------------------------
Hi, i could be wrong BUT...


loop
  getch (c)
  put "*"..
end loop
get VAR_Pass

That is what you have, i think you need to EXIT that loop to move on, So, Try something along the lines of adding,


var key: array char of boolean

%%You need this too
Input.KeyDown(key)

%%And add this at the bottom f the loop i posted from your code
if key (KEY_ENTER) then
   exit
end if


Try that, i didn't test it, but it might work

Im sure theres other ways to do this, but fiddle with mine :)

Bye, hope i helpd a bit


also, you have getch then put inside that loop, i think you might want to STORE the letters then link them up later to make your password, cause i dont think your code will work on that aspect...

-----------------------------------
[Gandalf]
Tue Sep 20, 2005 4:14 pm


-----------------------------------
There are quite many solutions, you could (according to your example):
loop
  getch (c)
  exit when c = '\n'
  put "*"..
end loop
get VAR_Pass 
or
loop
  getch (c)
  exit when ord (c) = 10
  put "*"..
end loop
get VAR_Pass 
and more.

-----------------------------------
Darkshining
Tue Sep 20, 2005 5:51 pm


-----------------------------------
i am so confused, can you please add it into my code instead of write the part because i don't know where to add it in. (i started a week ago)
and also, if using getch, how do i piece the Characters together to form my predefined password?

-----------------------------------
Cervantes
Tue Sep 20, 2005 6:29 pm


-----------------------------------
Keep a running tally:


var input := ""
var c : string (1)
loop
     getch (c)
     exit when c = chr (KEY_ENTER)
     input += c
end loop


Insert the exit when statement just after your getch line.

Don't use Input.KeyDown.  getch can do this fine, and intermingling the two will just cause problems.

-----------------------------------
Mr. T
Tue Sep 20, 2005 6:32 pm

Alex's Opinion
-----------------------------------
Don't use Input.KeyDown.  getch can do this fine, and intermingling the two will just cause problems.
I've heard that before, but I've never understood why?

-----------------------------------
Darkshining
Tue Sep 20, 2005 7:20 pm


-----------------------------------
i am not sure if this is suppose to happen, it opens a window and it says waiting for input. but i can't type anything.
View.Set("noecho")
var VAR_PWD : string := "55555" 
var VAR_Pass : string 
var d : int :=4 
for i : 1 .. d 
put "Please enter your password."  
var c:string(1) 
var input := "*"  
loop 
     getch (c) 
     exit when c = (KEY_DOWN_ARROW) 
     input += c 
end loop
get VAR_Pass 
if VAR_Pass not= VAR_PWD then 
put "Wrong password, ", i, " attemps." 
if i = d then 
put "Your account has been locked down for safety purposes." 
end if 
else put "Thank you for loggin in." 
exit 
end if 
end for

-----------------------------------
Cervantes
Tue Sep 20, 2005 7:25 pm


-----------------------------------
It has to do with what catches what.  So far as I have gone, there's only been one time when I've found it acceptable to use them at the same time.  That is when looking for ctrl+arrow and ctrl+shift+arrow within the same loop.  (This was when I was doing the textfield.)

Try playing around with it.  I think you'll find things will go arwy.  If they don't, try changing the order of the getch & Input.KeyDown (which appears first in the loop).  Post your findings. :wink:

Here's a bad example:


var keys : array char of boolean
var c : string (1) := 'a'

loop

    Input.KeyDown (keys)
    if hasch then    
        getch (c)
    end if
    

    put keys ('a')
    put c

    delay (50)

end loop


It could just be me, but that seemed to always return false and a, no matter what I pressed.  What's worse, I experienced an Internal Fatal Error.  Mind you, that's problem a problem with WINE.  In any case, there are places where you will get into trouble for combining these.  Try to find a pattern and explain the reason!

-----------------------------------
Cervantes
Tue Sep 20, 2005 7:34 pm


-----------------------------------
You're still using get.  And you're using getch as well.  Why?

And why are you adding c to input?  Judging by the initialization value of Input, it  seems to be a code to output with every keystroke, rather than a variable to store the input with each keystroke.  (The initialization value suggests one thing, the variable handle and the code suggest another thing.)

-----------------------------------
Darkshining
Tue Sep 20, 2005 7:37 pm


-----------------------------------
This is a working Password code. I wanted it to express the password as *s but instead it just shows nothing at all. But the good thing is, it works like this: press enter, type password, then press enter.
try it, password is 55555.
If someone can find the 2 problems i said above, then great!
thank you

View.Set("noecho")
var keys : array char of boolean
var VAR_PWD : string := "55555" 
var VAR_Pass : string 
var d : int :=4 
for i : 1 .. d 
put "Please enter your password."  
var c:string(1) 
var input := "*"  
loop 
     Input.KeyDown (keys)
     getch (c) 
     exit when c = (KEY_ENTER) 
     input += c 
end loop
get VAR_Pass 
if VAR_Pass not= VAR_PWD then 
put "Wrong password, ", i, " attemps." 
if i = d then 
put "Your account has been locked down for safety purposes." 
end if 
else put "Thank you for loggin in." 
exit 
end if 
end for


-----------------------------------
Cervantes
Tue Sep 20, 2005 7:53 pm


-----------------------------------
Indenting your code is very helpful for reading it.  Auto-indent by pressing F2.

Still, you're collecting everything you getch into "input" but never using the "input" variable anywhere!  You could just leave whatever you getch in 'c'.

Also, it is a good idea to get away from using get.  Try making this whole thing with getch, the way you originally planned it.

Here's a start:

View.Set ("nocursor")

var c : string (1)

var input := ""

put "Password:"

loop

    locate (1, length ("Password:") + 1)
    put repeat ("*", length (input))

    getch (c)
    exit when c = KEY_ENTER
    input += c

end loop

if input = "creative" then
    put "Successfully logged in."
else
    put "Intruder!"
end if


-----------------------------------
Darkshining
Tue Sep 20, 2005 9:12 pm


-----------------------------------
Ok, This is it.
Works, i am 99% sure it has no problems.
Thank you all for your efforts!
View.Set ("nocursor")

var pwd : string := "55555"
var d : int := 4
var s : string := "Please Enter Your Password Again."
var c : string (1)

var input := ""

put "Please Enter Your Password: "

for i : 1 .. d
    loop

        locate (1, length ("Please Enter Your Password: ") + 1)
        put repeat ("*", length (input))

        getch (c)
        exit when c = KEY_ENTER
        input += c

    end loop

    if input not= pwd and i < d then
        put "Wrong password, ", i, " attemps. ", s
        input := ""
    elsif
            input not= pwd and i >= d then
        put "Your account has been locked down for safety purposes."
    else
        put "Successfully logged in!"
    end if
end for


-----------------------------------
Cervantes
Wed Sep 21, 2005 3:05 pm


-----------------------------------
Almost.  What happens if you log in successfully on your first try?  Or any try, for that matter?  (Though if you successfully log in on your last try, there is no problem.) :wink:

-----------------------------------
Darkshining
Wed Sep 21, 2005 5:31 pm


-----------------------------------
I missed one word! lol
else 
        put "Successfully logged in!"
        exit 
    end if 
end for 
the exit.  :D

-----------------------------------
Cervantes
Wed Sep 21, 2005 5:50 pm


-----------------------------------
Good.  :)
Now, try using fonts!  I believe there's a tutorial in the [url=http://www.compsci.ca/v2/viewtopic.php?t=8808]walkthrough, though I cannot guarentee quality...  There's also the Turing Help Manual (F10).  Start by looking at Font.New, then learn Font.Draw, and finally Font.Free.

After that, use textfields!  (Although there are probably lots of things to learn between now and when you use textfields.  To pique your curiosity, though: [url=http://www.compsci.ca/v2/viewtopic.php?t=9329]Click here, and download the textfield.zip file.  Run Ex Field.t.
