password reseting backend fixes
This commit is contained in:
parent
c5d2fc3391
commit
74febc4891
|
@ -117,7 +117,7 @@ function account_gen_reset_code() {
|
||||||
|
|
||||||
if [[ $(date "+%s") -gt $((timestamp+3600)) || $2 == true ]]; then
|
if [[ $(date "+%s") -gt $((timestamp+3600)) || $2 == true ]]; then
|
||||||
sed -i "s/$user:$mail:$old_code:yes:$timestamp/$user:$mail:$new_code:yes:$new_timestamp/" secret/mail.dat
|
sed -i "s/$user:$mail:$old_code:yes:$timestamp/$user:$mail:$new_code:yes:$new_timestamp/" secret/mail.dat
|
||||||
echo -n "$new_code"$(date "+%d%m%y") | sha1sum | awk '{print $1}' | cut -c 1-10
|
account_get_reset_code "$user"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return 2
|
return 2
|
||||||
|
@ -127,6 +127,13 @@ function account_gen_reset_code() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#account_get_reset_code(username)
|
||||||
|
function account_get_reset_code() {
|
||||||
|
local data="$(cat secret/mail.dat | grep -P "^$1:")"
|
||||||
|
local code="$(awk -F: '{print $3}' <<< "$data")"
|
||||||
|
echo -n "$code"$(date "+%d%m%y") | sha1sum | awk '{print $1}' | cut -c 1-10
|
||||||
|
}
|
||||||
|
|
||||||
#reset_pwd(username, hash, password)
|
#reset_pwd(username, hash, password)
|
||||||
function reset_pwd() {
|
function reset_pwd() {
|
||||||
[[ "$1" == '' || "$2" == '' || "$3" == '' ]] && return
|
[[ "$1" == '' || "$2" == '' || "$3" == '' ]] && return
|
||||||
|
@ -134,7 +141,7 @@ function reset_pwd() {
|
||||||
local hash="$2"
|
local hash="$2"
|
||||||
local pass="$3"
|
local pass="$3"
|
||||||
|
|
||||||
if [[ "$(echo -n $(cat secret/mail.dat | grep -P "^$user:" | awk -F: '{print $3}')$(date "+%d%m%y") | sha1sum | awk '{print $1}' | cut -c 1-10)" == "$hash" ]]; then
|
if [[ "$(account_get_reset_code "$user")" == "$hash" ]]; then
|
||||||
delete_account "$user"
|
delete_account "$user"
|
||||||
register "$user" "$pass"
|
register "$user" "$pass"
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ if [[ "${post_data[login]}" != '' && "${post_data[password]}" != '' && "${post_d
|
||||||
status=$?
|
status=$?
|
||||||
verification="$RANDOM"
|
verification="$RANDOM"
|
||||||
|
|
||||||
echo "${post_data[login]}:$mail:$verification:no" >> secret/mail.dat
|
echo "${post_data[login]}:$mail:$verification:no:0" >> secret/mail.dat
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $status == 0 ]]; then
|
if [[ $status == 0 ]]; then
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
[[ "${post_data[login]}" == '' ]] && jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 0 "AAAA" && return
|
[[ "${post_data[login]}" == '' ]] && jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 0 "BAD REQUEST" && return
|
||||||
source "${cfg[namespace]}/code/common.sh"
|
source "${cfg[namespace]}/code/common.sh"
|
||||||
|
|
||||||
hash="$(account_gen_reset_code "${post_data[login]}")"
|
hash="$(account_gen_reset_code "${post_data[login]}")"
|
||||||
|
|
Loading…
Reference in a new issue