prompt_password()

new topic     » topic index » view thread      » older message » newer message

I had a need to prompt the user for a password on the console, and I was surprised to see that we didn't have this in the standard library already.

Can and/or should this be added?

public function prompt_password( sequence prompt = "Password: " ) 
-- prompt the user for some text, but do not display the characters 
 
    sequence answer = "" 
 
    puts( 1, prompt ) 
 
    atom key = wait_key() 
    while key != 13 do 
        -- exit on return 
 
        if key = 8 and length( answer ) then 
            -- backspace 
            answer = answer[1..$-1] 
        elsif key > 31 and key < 255 then 
            -- printable character 
            answer &= key 
        end if 
 
        key = wait_key() 
    end while 
 
    puts( 1, "\n" ) 
 
    return answer 
end function 

-Greg

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu