-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.zshrc.utils
More file actions
28 lines (27 loc) · 746 Bytes
/
.zshrc.utils
File metadata and controls
28 lines (27 loc) · 746 Bytes
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
get_random_chars() {
python3 - <<EOF
import string,random;
print("".join(random.choices(string.ascii_letters+string.digits,k=$1)))
EOF
}
# salt character length is followings to crypted password string in RHEL/CentOS/Fedora's kickstart
get_salted_pass() {
case $1 in
md5)
salt_character='$1$'`get_random_chars 8`
;;
sha256)
salt_character='$5$'`get_random_chars 16`
;;
sha512)
salt_character='$6$'`get_random_chars 16`
;;
*)
echo -e "please select hash function.\nmd5, or sha256, or sha512."
;;
esac
python3 - <<EOF
import crypt,getpass;
print(crypt.crypt(getpass.getpass(), "$salt_character"))
EOF
}