File tree Expand file tree Collapse file tree 4 files changed +44
-22
lines changed
Expand file tree Collapse file tree 4 files changed +44
-22
lines changed Original file line number Diff line number Diff line change @@ -48,12 +48,11 @@ is_password_valid
4848# Action #
4949# ----------------------------------------------------------#
5050
51- if [ -x ' /usr/bin/doveadm' ]; then
52- md5=$( /usr/bin/doveadm pw -s md5 -p " $password " )
53- else
54- md5=$( /usr/sbin/dovecotpw -s md5 -p " $password " )
55- fi
51+ # Generating hashed password
52+ salt=$( gen_password " $PW_MATRIX " " 8" )
53+ md5=" {MD5}$( $BIN /v-generate-password-hash md5 $salt <<< $password ) "
5654
55+ # Adding account info into password file
5756if [[ " $MAIL_SYSTEM " =~ exim ]]; then
5857 str=" $account :$md5 :$user :mail::$HOMEDIR /$user :$quota "
5958 echo $str >> $HOMEDIR /$user /conf/mail/$domain /passwd
Original file line number Diff line number Diff line change @@ -47,11 +47,9 @@ is_password_valid
4747# Action #
4848# ----------------------------------------------------------#
4949
50- if [ -x ' /usr/bin/doveadm' ]; then
51- md5=$( /usr/bin/doveadm pw -s md5 -p " $password " )
52- else
53- md5=$( /usr/sbin/dovecotpw -s md5 -p " $password " )
54- fi
50+ # Generating hashed password
51+ salt=$( gen_password " $PW_MATRIX " " 8" )
52+ md5=" {MD5}$( $BIN /v-generate-password-hash md5 $salt <<< $password ) "
5553
5654if [[ " $MAIL_SYSTEM " =~ exim ]]; then
5755 sed -i " /^$account :/d" $HOMEDIR /$user /conf/mail/$domain /passwd
Original file line number Diff line number Diff line change @@ -43,17 +43,6 @@ if [[ -z "$password" ]]; then
4343 exit 9
4444fi
4545
46- # Checking mkpasswd command
47- which mkpasswd > /dev/null 2>&1
48- if [ $? -ne 0 ]; then
49- # Activating fallback procedure
50- if [ -e " /usr/bin/yum" ]; then
51- yum install -y expect > /dev/null 2>&1
52- else
53- apt-get install -y expect > /dev/null 2>&1
54- fi
55- fi
56-
5746
5847# ----------------------------------------------------------#
5948# Action #
@@ -68,7 +57,7 @@ if [[ -z "$salt" ]] || [[ "${#salt}" -gt 8 ]]; then
6857fi
6958
7059# Generating SHA-512
71- hash=$( mkpasswd -m sha-512 -S $salt -s <<< $password )
60+ hash=$( $BIN /v-generate-password-hash sha-512 $salt <<< $password )
7261if [[ -z " $hash " ]]; then
7362 echo " Error: password missmatch"
7463 echo " $DATE $user $ip failed to login" >> $VESTA /log/auth.log
Original file line number Diff line number Diff line change 1+ #!/usr/local/vesta/php/bin/php
2+ <?php
3+ //# info: generate password hash
4+ //# options: HASH-METHOD SALT PASSWORD
5+ //
6+ //# The function generates password hash
7+
8+ // Checking arguments
9+ if ((empty ($ argv [1 ])) || (empty ($ argv [2 ]))) {
10+ echo "Error: not enought arguments \n" ;
11+ echo "Usage: " . $ argv [0 ] ." HASH-METHOD SALT PASSWORD \n" ;
12+ exit (1 );
13+ }
14+
15+ $ crypt = $ argv [1 ];
16+ $ salt = $ argv [2 ];
17+ if (empty ($ argv [3 ])) {
18+ $ password = file_get_contents ("php://stdin " );
19+ $ password = str_replace ("\n" ,'' ,$ password );
20+ } else {
21+ $ password = $ argv [3 ];
22+ }
23+
24+ // Generating MD5 hash
25+ if ($ crypt == 'md5 ' ) {
26+ $ hash = crypt ($ password , '$1$ ' .$ salt .'$ ' );
27+ }
28+
29+ // Generating SHA-512 hash
30+ if ($ crypt == 'sha-512 ' ) {
31+ $ hash = crypt ($ password , '$6$rounds=5000$ ' .$ salt .'$ ' );
32+ $ hash = str_replace ('$rounds=5000 ' ,'' ,$ hash );
33+ }
34+
35+ // Printing result
36+ echo $ hash . "\n" ;
You can’t perform that action at this time.
0 commit comments