Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Password and Usernames loggin
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Darkshining




PostPosted: Mon Sep 19, 2005 8:52 pm   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Sep 19, 2005 9:18 pm   Post subject: (No subject)

for *s, View.Set("noecho") and use getch char in a loop.

for a "database", just read/write to file.
Darkshining




PostPosted: Mon Sep 19, 2005 9:30 pm   Post subject: (No subject)

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




PostPosted: Mon Sep 19, 2005 9:36 pm   Post subject: (No subject)

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?)

Turing:

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




PostPosted: Tue Sep 20, 2005 10:32 am   Post subject: (No subject)

that is the code, it uses ****, but the enter key does not work now, is there a way around it?
code:
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




PostPosted: Tue Sep 20, 2005 1:43 pm   Post subject: (No subject)

Hi, i could be wrong BUT...

code:

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,

code:

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 Smile

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]




PostPosted: Tue Sep 20, 2005 4:14 pm   Post subject: (No subject)

There are quite many solutions, you could (according to your example):
code:
loop
  getch (c)
  exit when c = '\n'
  put "*"..
end loop
get VAR_Pass

or
code:
loop
  getch (c)
  exit when ord (c) = 10
  put "*"..
end loop
get VAR_Pass

and more.
Darkshining




PostPosted: Tue Sep 20, 2005 5:51 pm   Post subject: (No subject)

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?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue Sep 20, 2005 6:29 pm   Post subject: (No subject)

Keep a running tally:

code:

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




PostPosted: Tue Sep 20, 2005 6:32 pm   Post subject: Alex's Opinion

Cervantes wrote:
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




PostPosted: Tue Sep 20, 2005 7:20 pm   Post subject: (No subject)

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.
code:
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




PostPosted: Tue Sep 20, 2005 7:25 pm   Post subject: (No subject)

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:

Turing:

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




PostPosted: Tue Sep 20, 2005 7:34 pm   Post subject: (No subject)

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




PostPosted: Tue Sep 20, 2005 7:37 pm   Post subject: (No subject)

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

code:
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




PostPosted: Tue Sep 20, 2005 7:53 pm   Post subject: (No subject)

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:
Turing:

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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: