Computer Science Canada

A password TextField

Author:  mirus17 [ Sat May 20, 2006 7:27 pm ]
Post subject:  A password TextField

Hi, i am creating a password textfield, so i am wondering if there is any chance for the input to be displaying as asterics instead of characters like in a real password textfield they use on the net. P

Author:  Cervantes [ Sat May 20, 2006 7:48 pm ]
Post subject: 

Absolutely.

For an example, here's my textfield, complete with an example that shows two textfields in action, one for username, one for password.

Author:  mirus17 [ Sat May 20, 2006 8:09 pm ]
Post subject: 

so i looked at the code for couple of seconds and imho you have to always cls and update the screen for this to work. Please tell me if i am right cuz I cant do that in my prog. P.S. - is there a way you could give me the code only for asterics, not 26 kbytes of sophysticated operations that are hard for me to understand.

Author:  Cervantes [ Sat May 20, 2006 8:19 pm ]
Post subject: 

Well, I can show you this:
code:

var ch : char
var pword := ""

loop
    ch := getchar
    pword += ch
    locate (1, 1)
    put rep ("*", length (pword))
end loop

But that's probably too basic.

The thing is that the code for making the output in asterisks is only a very small part of the textfield. Most of the code is for other things. But if you're actually going to make a textfield as I have done, you'll need to code those other things as well.

Author:  mirus17 [ Sat May 20, 2006 8:28 pm ]
Post subject: 

well, i cant use your code in my program cuz it is my ISU and i have to write up a manual for my code so the teacher can understand (she doesnt know what a GUI.createbutton is) - and the above example is fine except if you press enter, it doesnt exit and is there a way of typing inside an already created textfield with the above example. by the way,Cervantes, maybe you could add me on msn so i could ask you some questions directly since we both are sitting at computers. my email is mirus17@hotmail.com.

Author:  Cervantes [ Sun May 21, 2006 8:40 am ]
Post subject: 

If doing it text based like that is fine, you can tune it up a bit yourself pretty easily.

code:

var ch : char
var pword := ""

loop
    ch := getchar
    % Here, insert code to handle special characters such as
    % the enter key to exit the loop and the backspace key to
    % remove a character. Here, I'll do the first one for you:
   
    if ch = KEY_BACKSPACE then
        pword := pword (1 .. * -1)
    else
        pword += ch
    end if
    locate (1, 1)
    put repeat ("*", length (pword))
end loop


As for IM'ing, you've got a whole lot better chance of finding me on the IRC Channel.

Author:  MysticVegeta [ Sun May 21, 2006 1:51 pm ]
Post subject: 

mirus17, please use the search button there have been countless password field posts here and "all" of them have the solutions posted, I am not being a jerk but its just that it saves everyone's time.
Cervantes: what happens when pword is an empty string and you hit backspace Wink
code:
var ch : char
var pword := ""

loop
    ch := getchar
    if ch = KEY_BACKSPACE and length (pword) > 0 then
        pword := pword (1 .. * -1)
    elsif ch = KEY_BACKSPACE and length (pword) = 0 then
        pword := ""
    else
        pword += ch
    end if
    cls
    for x : 1 .. length (pword)
        put "*" ..
    end for
end loop

Author:  Cervantes [ Sun May 21, 2006 2:10 pm ]
Post subject: 

MysticVegeta wrote:

Cervantes: what happens when pword is an empty string and you hit backspace Wink

Good point. Though the second condition in your elsif statement is redudant. And you've compared 'ch' to 'KEY_BACKSPACE' twice.
Mwahaha!

What was wrong with using repeat?

Author:  mirus17 [ Sun May 21, 2006 10:40 pm ]
Post subject: 

thanks a lot guys, i found what i was looking for

Author:  MysticVegeta [ Mon May 22, 2006 10:31 am ]
Post subject: 

Cervantes wrote:
What was wrong with using repeat?

Wow, I never knew repeat existed! cool function and here I used loops to catenate strings.... thanks for the pointer. maybe I should look more at the F10 reference...


: