Skip to content

Commit

Permalink
[ansible] Replace random with secrets for generating password salts
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-manu committed Sep 5, 2022
1 parent eb3105a commit e09170f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ansible/filter_plugins/utilities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
import random
import secrets
import base64
import crypt

Expand Down Expand Up @@ -41,6 +41,6 @@ def sha512_hash(self, pw, rounds):
if not _SHA512_MIN_ROUNDS <= rounds <= _SHA512_MAX_ROUNDS:
raise ValueError("sha512 password hashing requires a rounds value between "
f"{ _SHA512_MIN_ROUNDS } and { _SHA512_MAX_ROUNDS }")
salt = base64.b64encode(random.randbytes(_SHA512_SALT_BYTES)).decode("utf-8")
salt = base64.b64encode(secrets.token_bytes(_SHA512_SALT_BYTES)).decode("utf-8")
return crypt.crypt(pw, f"{ _SHA512_PREFIX }rounds={ rounds }${ salt }")

0 comments on commit e09170f

Please sign in to comment.