summaryrefslogtreecommitdiff
path: root/example/passwdprompt
blob: 163e493068425f6227a4a3b9b0125d11c66cd859 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/depot/path/expect

# This script prompts for a passwd from stdin while echoing *'s

# Prompt MUST be passed as argument to avoid falling into the classic
# prompt-before-echo-has-been-disabled mistake.

proc getpass {prompt} {
    set sttyOld [stty -echo raw]
    send_user $prompt

    set timeout -1
    set passwd ""

    expect {
	-re "\r" {
	    send_user \r\n
	} -re "\010|\177" {
	    if {[string length $passwd] > 0} {
		# not all ttys support destructive spaces
		send "\010 \010"
		regexp (.*). $passwd x passwd
	    }
	    exp_continue
	} -re . {
	    send_user *
	    append passwd $expect_out(0,string)
	    exp_continue
	}
    }
    eval stty $sttyOld
    return $passwd
}

puts "The password you entered was: [getpass "Password: "]"