this is a stupid question ... honestly i don't really have a clue at the moment and am pretty novice to python...
I'm currently wrecking my head on a python script to generate a random password. I found a good start from here example by 'Omid Raha'
edit: on revist, this example is far to complex for something that appears to have much simpler ways of performing the same task...
import random
import hashlib
import time
"""
This script is adapted from an example found here:https://stackoverflow.com/questions/18319101/whats-the-best-way-to-generate-random-strings-of-a-specific-length-in-python ; originally provided by user 'Omid Raha'
"""
SECRET_KEY = 'ffdsat9asdf5o5u9HKHvurtiasdf1tg1V36jyasdfSv8Ppin9O'
try:
random = random.SystemRandom()
using_sysrandom = True
except NotImplementedError:
import warnings
warnings.warn('A secure pseudo-random number generator is not available '
'on your system. Falling back to Mersenne Twister.')
using_sysrandom = False
def get_random_string(length=12,
allowed_chars='abcdefghijklmnopqrstuvwxyz'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
'%*/-_@'):
"""
Returns a securely generated random string.
The default length of 12 with the a-z, A-Z, 0-9 character set returns
a 71-bit value. log_2((26+26+10)^12) =~ 71 bits
"""
if not using_sysrandom:
# This is ugly, and a hack, but it makes things better than
# the alternative of predictability. This re-seeds the PRNG
# using a value that is hard for an attacker to predict, every
# time a random string is required. This may change the
# properties of the chosen random sequence slightly, but this
# is better than absolute predictability.
random.seed(
hashlib.sha256(
("%s%s%s" % (
random.getstate(),
time.time(),
SECRET_KEY)).encode('utf-8')
).digest())
return ''.join(random.choice(allowed_chars) for i in range(length))
print (get_random_string)
simply returns:
<function get_random_string at 0x1034f7848>
I have no clue what this means... or if I'm even properly executing the script.
edit:
thank you, for reading