-
Notifications
You must be signed in to change notification settings - Fork 0
/
password_manager.sh
executable file
·110 lines (89 loc) · 2.21 KB
/
password_manager.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
PSSWORD_DIR="passwords.txt"
function add_password {
echo "Enter the account name:"
read account_name
echo "Enter the username:"
read username
echo "Enter the password:"
read password
echo "$account_name:$username:$password" >> $PSSWORD_DIR
echo "Password added successfully in sanilo password manager :)"
}
function get_password {
echo "Enter the account name:"
read account_name
password=$(grep "^$account_name:" $PSSWORD_DIR | cut -d ":" -f 3)
if [ -z "$password" ]
then
echo "Password not found!"
else
echo "Password: $password"
fi
}
function update_password {
echo "Enter the account name:"
read account_name
password=$(grep "^$account_name:" $PSSWORD_DIR | cut -d ":" -f 3)
if [ -z "$password" ]
then
echo "Password not found!"
else
echo "Enter the new password:"
read new_password
sed -i "s/$account_name:.*:$password/$account_name:$username:$new_password/g" $PSSWORD_DIR
echo "Password updated successfully in sanilo password manager :)"
fi
}
function delete_password {
echo "Enter the account name:"
read account_name
password=$(grep "^$account_name:" $PSSWORD_DIR | cut -d ":" -f 3)
if [ -z "$password" ]
then
echo "Password not found!"
else
sed -i "/^$account_name:/d" $PSSWORD_DIR
echo "Password deleted successfully in sanilo password manager :)"
fi
}
function show_help {
echo "Usage: password_manager.sh [OPTION]"
echo "Options:"
echo " -sa, --add Add a new password 🔐"
echo " -sg, --get Get an existing password 👁"
echo " -su, --update Update an existing password 💅"
echo " -sd, --delete Delete an existing password 🔥"
echo " -h, --help Show this help message 🙄"
}
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-sa|--add)
add_password
shift
;;
-sg|--get)
get_password
shift
;;
-su|--update)
update_password
shift
;;
-sd|--delete)
delete_password
shift
;;
-h|--help)
show_help
shift
;;
*)
echo "Unknown option: $key"
show_help
exit 1
;;
esac
done