Is it possible to specify a custom Base_64 dictionary when encoding data within passlib?
I have a requirement to generate 'scrypt' encoded passwords on a system that does not allow the '+' character within its configuration files.
More specifically the custom dictionary used is = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
Opposed to the standard dictionary = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
Using the code:
import sys
import re
from passlib.hash import scrypt
char = re.compile(r'[a-zA-Z0-9()!#$%^&*.,+=_-]')
def main():
try:
pwd = input('\n' + 'Enter a Plain Text Password to Encrypt: ')
except KeyboardInterrupt:
sys.exit(0)
else:
if len(pwd) > 64:
print ('Password must be between 1 and 64 characters. Try again.')
main()
else:
if (char.match(pwd)):
hash = str(scrypt.using(rounds=14, salt_size=10).hash(pwd))[21:]
print ('\n Your hash is: ' + hash)
else:
print ('Illegal characters. Try again.')
main()
main()
It will occasionally output '+' characters, which my system does not support.
Your hash is: $o/ReK+U8JyRkbA$W6zFHBmebC4LwkTN+rB8kSgUbDK0Zo4p2z7CCwvJOXk
If I'm not mistaken, the characters also have to be in the correct order within the dictionary.
Is there a way to specify a custom dictionary with passlib? Or is there a better way to achieve this?
The 'salt' is also encoded using the same standard dictionary, which also needs to make use of the custom dictionary.
-Brett