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

Username:   Password: 
 RegisterRegister   
 Passwords in textfields?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
theuberk




PostPosted: Mon Jan 09, 2006 6:54 pm   Post subject: Passwords in textfields?

I was just wondering how I would input a password in a textfield. I know that I can use getch and save the character in a string and then put a * in place of the character, but how would I do this in a textfield?
Sponsor
Sponsor
Sponsor
sponsor
pavol




PostPosted: Mon Jan 09, 2006 8:08 pm   Post subject: (No subject)

im not entirely sure, but you might be able to check every time a key is pressed and when it is, store the value of the key in a varibale. and then insead of writing the letter in the textfield you write an *. then you'd also have a variable counting how many keys have been pressed (letters have been entered), so the program knows how many * to put in the textfield.
hope it helps (and i hope it's at least possible) Very Happy
Cervantes




PostPosted: Mon Jan 09, 2006 9:26 pm   Post subject: (No subject)

You want to make your own textfields? Wink
theuberk




PostPosted: Mon Jan 16, 2006 6:58 pm   Post subject: (No subject)

Thanks for your help guys. I figured it out! Here's the procedure if anyone wants to use it:


tf = the text field widgit ID
text = the variable in which you'd like to save the inputted text


code:

procedure HideText (tf : int, var text : string)
    var tftext : string := GUI.GetText (tf)
    var current : string := ""
    for i : 1 .. length (tftext)
        if tftext (i) not= "*" then
            text := text + tftext (i)
        end if
    end for

    if length (tftext) < length (text) then
        for i : 1 .. length (text) - 1
            current := current + text (i)
        end for
        text := current
    end if

    var newText : string := "*"
    for i : 1 .. length (tftext)
        if i <= 1 then
            newText := "*"
            tftext := newText
        else
            newText := newText + "*"
            tftext := newText
        end if
    end for
    GUI.SetText (tf, tftext)
    GUI.SetSelection (tf, length (tftext) + 1, length (tftext) + 1)
end HideText
[/b]
MysticVegeta




PostPosted: Mon Jan 16, 2006 7:28 pm   Post subject: (No subject)

yes but it does now serve the purpose, cause after you enter the pass then you press enter inorder to blank it, meanwhile it is still visible to others Wink So if you want to make it accurate you have to make it "asterisk" it every character that a person types, just like how Cervantes did it.
theuberk




PostPosted: Mon Jan 16, 2006 7:40 pm   Post subject: (No subject)

Sorry, I didn't specify. You have to run this procedure constantly within the GUI.ProcessEvent loop, with a small delay to avoid flickering. For Example:

code:

loop
    exit when GUI.ProcessEvent
    HideText (passwordtf, password)
    delay (75)
end loop
[/code]
MysticVegeta




PostPosted: Mon Jan 16, 2006 8:34 pm   Post subject: (No subject)

ok since you tried, I will tell you an easier way:

code:
import GUI

proc HideText (text : string)
    put "You entered '", text, "'"
end HideText

var tf := GUI.CreateTextField (100, 200, 100, "", HideText)
GUI.SetEchoChar (tf, '*')

loop
    exit when GUI.ProcessEvent
end loop

theuberk




PostPosted: Mon Jan 16, 2006 9:24 pm   Post subject: (No subject)

Doesn't that mean that I'd have to use the altered TextFieldClass.tu file?
Sponsor
Sponsor
Sponsor
sponsor
Rasta Fella




PostPosted: Mon Jan 16, 2006 9:35 pm   Post subject: (No subject)

Quote:
Doesn't that mean that I'd have to use the altered TextFieldClass.tu file?


Well, you can but Crevantes way is more efficient. check his link.
MysticVegeta




PostPosted: Mon Jan 16, 2006 10:32 pm   Post subject: (No subject)

theuberk wrote:
Doesn't that mean that I'd have to use the altered TextFieldClass.tu file?


You mean as in Turing 4.0.5? You dont have 4.0.5?
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 1  [ 10 Posts ]
Jump to:   


Style:  
Search: