我想保护一个子域,其中用户只能访问 1 天。是否可以设置一个 cron 作业,每天自动用新密码更新 .htpasswd 文件?
答案1
您可能应该使用专门用于执行此操作的应用程序,而不是使用 cron 来破解某些东西。但是,如果您必须将其变成 hackalicious...
您必须以“批处理模式”运行 htpasswd。摘自 htpasswd 手册页:
htpasswd -mb /usr/web/.htpasswd-all jones Pwd4Steve
Encrypts the password from the command line (Pwd4Steve)
using the MD5 algorithm, and stores it in the specified
file.
类似这样的事情应该可以工作:
FILE=/path/to/your/htaccess/file
# There are a bunch of ways to get a new password, this is one:
NEW_PASS=`cat /dev/urandom|tr -dc "a-zA-Z0-9-_\$\?"|fold -w 9|head -n1`
HTPASSWD=/usr/bin/htpasswd
WEB_USER=samuel_l_jackson
# This should do it
$HTPASSWD -b $FILE $WEB_USER $NEW_PASS
# You'll probably want to email the password to your user,
# so they can actually use the new password