Posted to tcl by rmax at Fri Aug 04 12:37:17 GMT 2017view raw
- package require Tk
- package require sha1
- package require http
- package require tls
- set URL https://haveibeenpwned.com/api/v2/pwnedpassword/
- http::register https 443 ::tls::socket
- http::config -useragent "Tcl/Tk pwned password checker"
- entry .in -font fixed -textvariable in -show *
- label .out -width 40 -height 3
- pack .in .out -fill x
- proc pwned {pass} {
- .out configure -bg grey -text "processing ..."
- set tok [http::geturl $::URL/[::sha1::sha1 $pass]]
- switch -- [http::ncode $tok] {
- 200 { .out configure -bg red -text "You haven been pwned! :(" }
- 404 {
- .out configure -bg green \
- -text "Your password is not in the database! :)"
- }
- default { .out configure -text [http::code $tok] }
- }
- http::cleanup $tok
- set ::in ""
- }
- bind .in <Control-BackSpace> {
- set in ""
- }
- bind .in <Return> {
- pwned $in
- set in ""
- }