Posted to tcl by rmax at Fri Aug 04 12:37:17 GMT 2017view raw

  1. package require Tk
  2. package require sha1
  3. package require http
  4. package require tls
  5.  
  6. set URL https://haveibeenpwned.com/api/v2/pwnedpassword/
  7.  
  8. http::register https 443 ::tls::socket
  9. http::config -useragent "Tcl/Tk pwned password checker"
  10.  
  11. entry .in -font fixed -textvariable in -show *
  12. label .out -width 40 -height 3
  13.  
  14. pack .in .out -fill x
  15.  
  16. proc pwned {pass} {
  17. .out configure -bg grey -text "processing ..."
  18. set tok [http::geturl $::URL/[::sha1::sha1 $pass]]
  19. switch -- [http::ncode $tok] {
  20. 200 { .out configure -bg red -text "You haven been pwned! :(" }
  21. 404 {
  22. .out configure -bg green \
  23. -text "Your password is not in the database! :)"
  24. }
  25. default { .out configure -text [http::code $tok] }
  26. }
  27. http::cleanup $tok
  28. set ::in ""
  29. }
  30.  
  31. bind .in <Control-BackSpace> {
  32. set in ""
  33. }
  34.  
  35. bind .in <Return> {
  36. pwned $in
  37. set in ""
  38. }
  39.