Skip to content

Instantly share code, notes, and snippets.

@wknapik
Created June 21, 2019 09:41
Show Gist options
  • Save wknapik/6f45dfbbdc5bacb84290fed12d7a2f5d to your computer and use it in GitHub Desktop.
Save wknapik/6f45dfbbdc5bacb84290fed12d7a2f5d to your computer and use it in GitHub Desktop.
Verify whether a hash generated with htpasswd matches a password
% htpasswd -nb foo bar >passwd
% ./chkpasswd.exp passwd foo bar
% echo "$?"
# 0 = match, 1 = no match
#!/usr/bin/env expect
log_user 0
set file [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
spawn htpasswd -v $file $user
expect "Enter password: "
send "$password\r"
expect "Password for user $user correct." { exit 0 }
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment