Sophie

Sophie

distrib > Mageia > 5 > x86_64 > by-pkgid > a68a11d7b2fdd65fa640544faac65cb2 > files > 39

expect-examples-5.43.0-26.mga5.x86_64.rpm

#!/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: "]"