11#! /bin/bash
22# info: check user password
3- # options: USER PASSWORD [IP]
3+ # options: USER PASSWORD [IP] [RETURN_HASH]
44#
55# example: v-check-user-password admin qwerty1234
66#
1414user=$1
1515password=$2 ; HIDE=2
1616ip=${3-127.0.0.1}
17+ return_hash=$4
1718
1819# Includes
1920# shellcheck source=/etc/hestiacp/hestia.conf
@@ -31,11 +32,11 @@ date=$(echo "$time_n_date" |cut -f 2 -d \ )
3132# Verifications #
3233# ----------------------------------------------------------#
3334
34- check_args ' 2' " $# " ' USER PASSWORD'
35+ check_args ' 2' " $# " ' USER PASSWORD RETURN_HASH '
3536is_format_valid ' user'
3637
3738# Checking user
38- if [ ! -d " $HESTIA /data/users/$user " ] && [ " $user " != ' root ' ] ; then
39+ if [ ! -d " $HESTIA /data/users/$user " ]; then
3940 echo " Error: password missmatch"
4041 echo " $date $time $user $ip failed to login" >> $HESTIA /log/auth.log
4142 exit 9
6364 salt=$( echo " $shadow " | cut -f 3 -d \$ )
6465 method=$( echo " $shadow " | cut -f 2 -d \$ )
6566 if [ " $method " = " y" ]; then
66- echo " Unsuported hash method" ;
67- exit 1;
67+ method=" yescrypt"
6868 elif [ " $method " -eq ' 1' ]; then
6969 method=' md5'
7070 elif [ " $method " -eq ' 6' ]; then
@@ -85,13 +85,22 @@ if [ -z "$salt" ]; then
8585 exit 9
8686fi
8787
88- # Generating hash
89- set -o noglob
90- hash=$( $BIN /v-generate-password-hash " $method " " $salt " <<< " $password" )
91- if [[ -z " $hash " ]]; then
92- echo " Error: password missmatch"
93- echo " $date $time $user $ip failed to login" >> $HESTIA /log/auth.log
94- exit 9
88+ if [ " $method " = " yescrypt" ]; then
89+ hash=$( mkpasswd " $password " " $shadow " )
90+ if [ $? -ne 0 ]; then
91+ echo " Error: password missmatch"
92+ echo " $date $time $user $ip failed to login" >> $HESTIA /log/auth.log
93+ exit 9
94+ fi
95+ else
96+ # Generating hash
97+ set -o noglob
98+ hash=$( $BIN /v-generate-password-hash " $method " " $salt " <<< " $password" )
99+ if [[ -z " $hash " ]]; then
100+ echo " Error: password missmatch"
101+ echo " $date $time $user $ip failed to login" >> $HESTIA /log/auth.log
102+ exit 9
103+ fi
95104fi
96105
97106# Checking hash
106115# Hestia #
107116# ----------------------------------------------------------#
108117
118+ if [ -n " $return_hash " ]; then
119+ echo $hash ;
120+ fi
109121# Logging
110122echo " $date $time $user $ip successfully logged in" >> $HESTIA /log/auth.log
111123
0 commit comments