Skip to content

Commit ea22b39

Browse files
committed
Handle DES passwords
1 parent 5e861eb commit ea22b39

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

bin/v-check-user-password

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,24 @@ fi
4949
#----------------------------------------------------------#
5050

5151
# Parsing user's salt
52-
shadow=$(grep "^$user:" /etc/shadow)
53-
salt=$(echo "$shadow" |cut -f 3 -d \$)
54-
method=$(echo "$shadow" |cut -f 2 -d \$)
55-
if [ "$method" -eq '1' ]; then
56-
method='md5'
52+
shadow=$(grep "^$user:" /etc/shadow | cut -f 2 -d :)
53+
54+
if echo "$shadow" | grep -qE '^\$[0-9a-z]+\$[^\$]+\$'
55+
then
56+
salt=$(echo "$shadow" |cut -f 3 -d \$)
57+
method=$(echo "$shadow" |cut -f 2 -d \$)
58+
if [ "$method" -eq '1' ]; then
59+
method='md5'
60+
elif [ "$method" -eq '6' ]; then
61+
method='sha-512'
62+
else
63+
echo "Error: password missmatch"
64+
echo "$DATE $TIME $user $ip failed to login" >> $VESTA/log/auth.log
65+
exit 9
66+
fi
5767
else
58-
method='sha-512'
68+
salt=${shadow:0:2}
69+
method='des'
5970
fi
6071

6172
if [ -z "$salt" ]; then
@@ -64,7 +75,7 @@ if [ -z "$salt" ]; then
6475
exit 9
6576
fi
6677

67-
# Generating SHA-512
78+
# Generating hash
6879
hash=$($BIN/v-generate-password-hash $method $salt <<< $password)
6980
if [[ -z "$hash" ]]; then
7081
echo "Error: password missmatch"

bin/v-generate-password-hash

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,10 @@ if ($crypt == 'htpasswd' ) {
3737
$hash = crypt($password, base64_encode($password));
3838
}
3939

40+
// Generating DES hash
41+
if ($crypt == 'des' ) {
42+
$hash = crypt($password, $salt);
43+
}
44+
4045
// Printing result
4146
echo $hash . "\n";

0 commit comments

Comments
 (0)