
-----------------------------------
mirus17
Sat May 20, 2006 7:27 pm

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

-----------------------------------
Cervantes
Sat May 20, 2006 7:48 pm


-----------------------------------
Absolutely.

For an example, here's [url=http://www.compsci.ca/v2/viewtopic.php?t=9329]my textfield, complete with an example that shows two textfields in action, one for username, one for password.

-----------------------------------
mirus17
Sat May 20, 2006 8:09 pm


-----------------------------------
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.

-----------------------------------
Cervantes
Sat May 20, 2006 8:19 pm


-----------------------------------
Well, I can show you this:

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.

-----------------------------------
mirus17
Sat May 20, 2006 8:28 pm


-----------------------------------
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.

-----------------------------------
Cervantes
Sun May 21, 2006 8:40 am


-----------------------------------
If doing it text based like that is fine, you can tune it up a bit yourself pretty easily.


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 [url=http://www.compsci.ca/wiki/index.php?title=IRC_channel]IRC Channel.

-----------------------------------
MysticVegeta
Sun May 21, 2006 1:51 pm


-----------------------------------
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: 
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


-----------------------------------
Cervantes
Sun May 21, 2006 2:10 pm


-----------------------------------

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?

-----------------------------------
mirus17
Sun May 21, 2006 10:40 pm


-----------------------------------
thanks a lot guys, i found what i was looking for

-----------------------------------
MysticVegeta
Mon May 22, 2006 10:31 am


-----------------------------------
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...
