From 08a71321b77de36912efb39bc679dbe35122f53f Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Fri, 7 May 2021 13:39:27 +0500 Subject: [PATCH] epic password change --- changepassword.sh | 110 ++++++++++++++++++++++++++++++++-------------- mainmenu.sh | 3 -- 2 files changed, 78 insertions(+), 35 deletions(-) diff --git a/changepassword.sh b/changepassword.sh index 58cfdd9..d429346 100644 --- a/changepassword.sh +++ b/changepassword.sh @@ -1,40 +1,86 @@ +read -s -p 'Enter Current Password: ' OLD_PASSWORD +echo "" +echo "" + +while true; do +read -s -p 'Enter New Password: ' NEW_PASSWORD +echo "" +read -s -p 'Repeat New Password: ' REPEAT_NEWPASSWORD +echo "" +if [ "$NEW_PASSWORD" = "$REPEAT_NEWPASSWORD" ] +then + sleep 0.2 + echo "" + break +else + echo "${red}Password do not match${reset}" + echo "Try again" + echo "" +fi +done + +while true; do +echo "Select OTP Method:" +echo "1 - Mobile" +echo "2 - Email" +echo "" +read -p "Please input: " OTPCHANNEL + +if [ "$OTPCHANNEL" = "1" ] || [ "$OTPCHANNEL" = "mobile" ] + then + OTPCHANNEL=mobile + break +elif [ "$OTPCHANNEL" = "2" ] || [ "$OTPCHANNEL" = "email" ] + then + OTPCHANNEL=email + break +else + echo "${red}Invalid Input${reset}" + echo "" +fi +done + +OLDPASSCHECHECK=$(curl -s -b $COOKIE $BML_URL/user/changepassword \ + --data-raw currentPassword=$OLD_PASSWORD \ + --data-raw newPassword=$NEW_PASSWORD \ + --data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \ + --data-raw channel=$OTPCHANNEL \ + --compressed \ + | jq -r .success) + +if [ "$OLDPASSCHECHECK" != "true" ] + then + source changepassword.sh +else + : +fi - read -s -p 'Enter Current Password: ' OLD_PASSWORD - echo "" - read -s -p 'Enter New Password: ' NEW_PASSWORD - echo "" - read -s -p 'Repeat New Password: ' REPEAT_NEWPASSWORD - if [ "$NEW_PASSWORD" = "$REPEAT_NEWPASSWORD" ] - then - echo "Select OTP Method:" - echo "1 - Mobile" - echo "2 - Email" - echo "" - echo "Please input: " - read -r OTPCHANNEL - if [ "$OTPCHANNEL" = "1" ] - then - OTPCHANNEL=mobile - elif [ "$OTPCHANNEL" = "2" ] - then - OTPCHANNEL=email - else - echo "${red}Invalid Input${reset}" - fi +if [ "$OTPCHANNEL" = "mobile" ] + then + ECHOOTPCHANNEL=$PHONE +elif [ "$OTPCHANNEL" = "email" ] + then + ECHOOTPCHANNEL=$EMAIL +fi - - curl -s -b $COOKIE $BML_URL/user/changepassword' \ +echo "" +echo "${lightgreen}OTP sent to ${yellow}${ECHOOTPCHANNEL}${reset}" +read -p 'Enter OTP: ' OTP +echo "" +PASSCHANGED=$(curl -s -b $COOKIE $BML_URL/user/changepassword \ --data-raw currentPassword=$OLD_PASSWORD \ --data-raw newPassword=$NEW_PASSWORD \ --data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \ --data-raw channel=$OTPCHANNEL \ - --compressed - - curl -s -b $COOKIE $BML_URL/user/changepassword' \ - --data-raw currentPassword=$OLD_PASSWORD \ - --data-raw newPassword=$NEW_PASSWORD \ - --data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \ - --data-raw channel=$OTPCHANNEL --data-raw otp=$OTP \ - --compressed + --compressed \ + | jq -r .success) + +if [ "$PASSCHANGED" != "true" ] + then + echo "${red}Failed to change password${reset}" +else + echo "${lightgreen}Password changed succesfully ${reset}" + source settings-menu.sh +fi diff --git a/mainmenu.sh b/mainmenu.sh index e3077f4..7dcaf5d 100644 --- a/mainmenu.sh +++ b/mainmenu.sh @@ -39,9 +39,6 @@ elif [ "$MENU" = "5" ] source services.sh elif [ "$MENU" = "6" ] then - echo "WIP" -# sleep 2 -# source mainmenu.sh source settings-menu.sh elif [ "$MENU" = "clear" ] then