separated password.sh and login.sh

This commit is contained in:
Shihaam Abdul Rahman 2021-04-28 01:46:14 +05:00
parent f79d9fb2ef
commit 46424c86ee
4 changed files with 68 additions and 52 deletions

56
bml.sh
View File

@ -1,4 +1,8 @@
#!/bin/bash #!/bin/bash
#Setting intial variables
BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api' BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api'
COOKIE=/tmp/bmlcookie COOKIE=/tmp/bmlcookie
@ -7,55 +11,5 @@ red=`tput setaf 1`
green=`tput setaf 2` green=`tput setaf 2`
reset=`tput sgr0` reset=`tput sgr0`
#importing saved credentials
source .env 2> /dev/null
#what to do if credentials not saved
if [ "$BML_USERNAME" = "" ]
then
echo ${red}Credentials not found in .env file${reset}
echo ""
read -p 'Username: ' BML_USERNAME
read -s -p 'Password: ' BML_PASSWORD
echo ""
read -p 'Do you want to save login? [Y/N] ' SAVE_LOGIN
if [ "$SAVE_LOGIN" = "Y" ]
then
echo BML_USERNAME=$BML_USERNAME > .env
echo BML_PASSWORD=$BML_PASSWORD >> .env
else
:
fi
echo ""
else
:
fi
#login and generate cookie
LOGIN=$(curl -s -c $COOKIE $BML_URL/login \
--data-raw username=$BML_USERNAME \
--data-raw password=${BML_PASSWORD} \
--compressed \
| jq -r .success)
#check if login was success
if [ "$LOGIN" = "true" ]
then
#Requesting for User profile after login and regex to grap the Full name
NAME=$(curl -s -b $COOKIE $BML_URL/profile \
| awk -F 'fullname":"' '{print $2}' \
| cut -f1 -d '"')
#display a Welcome message with fullname
echo ""
echo ${green}Welcome ${reset}$NAME
# curl -s -b $COOKIE $BML_URL/userinfo
echo ""
source mainmenu.sh
else
#Display error if login was not succuessfull and delete cookie
echo "${red}An error occured, Please check Username and Password" 1>&2
rm $COOKIE 2> /dev/null
exit
fi
source password.sh

28
login.sh Normal file
View File

@ -0,0 +1,28 @@
#!/bin/bash
#login and generate cookie
LOGIN=$(curl -s -c $COOKIE $BML_URL/login \
--data-raw username=$BML_USERNAME \
--data-raw password=${BML_PASSWORD} \
--compressed \
| jq -r .success)
#check if login was success
if [ "$LOGIN" = "true" ]
then
#Requesting for User profile after login and regex to grap the Full name
NAME=$(curl -s -b $COOKIE $BML_URL/profile \
| awk -F 'fullname":"' '{print $2}' \
| cut -f1 -d '"')
#display a Welcome message with fullname
echo ""
echo ${green}Welcome ${reset}$NAME
# curl -s -b $COOKIE $BML_URL/userinfo
echo ""
source mainmenu.sh
else
#Display error if login was not succuessfull and delete cookie
echo "${red}An error occured, Please check Username and Password" 1>&2
rm $COOKIE 2> /dev/null
exit
fi

View File

@ -1,4 +1,4 @@
echo "Menu" echo "Main Menu"
echo "" echo ""
echo "1 - Accounts" echo "1 - Accounts"
echo "2 - Transfer" echo "2 - Transfer"

34
password.sh Normal file
View File

@ -0,0 +1,34 @@
#!/bin/bash
#importing saved credentials
source .env 2> /dev/null
#what to do if credentials not saved
if [ "$BML_USERNAME" = "" ]
then
echo ${red}Credentials not found in .env file${reset}
echo ""
read -p 'Username: ' BML_USERNAME
read -s -p 'Password: ' BML_PASSWORD
echo ""
echo "Do ${red}NOT${reset} save password if password contain '|' '^' '$' '&' ';' ':' '(' ')' "
read -p 'Do you want to save login? [y/N] ' SAVE_LOGIN
if [ "$SAVE_LOGIN" = "Y" ]
then
echo BML_USERNAME=$BML_USERNAME > .env
echo BML_PASSWORD=$BML_PASSWORD >> .env
elif [ "$SAVE_LOGIN" = "y" ]
then
echo BML_USERNAME=$BML_USERNAME > .env
echo BML_PASSWORD=$BML_PASSWORD >> .env
else
:
fi
echo ""
else
:
fi
source login.sh