3 # Changes a user's password using the Users and Groups module. Also changes
4 # the password in other modules.
7 $ENV{'WEBMIN_CONFIG'} ||= "/etc/webmin";
8 $ENV{'WEBMIN_VAR'} ||= "/var/webmin";
9 if ($0 =~ /^(.*\/)[^\/]+$/) {
13 $0 = "$pwd/change-passwd.pl";
16 if ($ARGV[0] eq "--old" || $ARGV[0] eq "-old") {
20 @ARGV == 1 || &errordie("usage: change-passwd.pl [-old] <username>");
21 if (&foreign_installed("useradmin") != 1) {
22 &errordie("Users and Groups module is not supported on this OS");
25 # Find the user, either in local password file or LDAP
26 $user = &find_user($ARGV[0]);
27 $user || &errordie("User $ARGV[0] does not exist");
31 # Ask for the old password
32 print "(current) UNIX password: ";
35 &unix_crypt($old, $user->{'pass'}) eq $user->{'pass'} ||
36 &errordie("Old password is incorrect");
40 print "New password: ";
43 print "Retype new password: ";
46 $pass eq $again || &errordie("Passwords don't match");
48 # Check password sanity
49 $err = &useradmin::check_password_restrictions($pass, $ARGV[0]);
50 &errordie($err) if ($err);
53 &change_password($user, $pass, 1);