diff --git a/User Hash Generator/README.md b/User Hash Generator/README.md new file mode 100644 index 00000000..c2886c84 --- /dev/null +++ b/User Hash Generator/README.md @@ -0,0 +1,13 @@ +# User Hash Generator + +I used this script in a flask website to use another identifier beside user id. It creates hashes with very low possibility of collusion. You may consider its other use cases. + +## Getting Started + +To demonstrate generator, a working terminal program is integrated. To try, type in terminal: + +`$ python3 hash.py` + +Notice: 'python3' keyword may be 'py' or 'python' for your system. \\ +
+To use in your own project, examine the code. \ No newline at end of file diff --git a/User Hash Generator/hash.py b/User Hash Generator/hash.py new file mode 100644 index 00000000..222c84f4 --- /dev/null +++ b/User Hash Generator/hash.py @@ -0,0 +1,24 @@ +from time import time +from random import randint + +def user_hash_generator(): + n = 1 + while True: + timestamp = int(time()*1000) + hash_string = hex(hash((timestamp/(randint(1, 250)+n)) + * (randint(1, 10)*5*n)))[2:14] + n += 1 + yield hash_string + +if __name__ == '__main__': + print('Generator will create a random hash when you press only Enter.\ + \nTo exit, press any other button then Enter.') + + hasher = user_hash_generator() + while True: + ch = input() + if ch == '': + print(next(hasher)) + else: + print('Terminated') + break