Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions User Hash Generator/README.md
Original file line number Diff line number Diff line change
@@ -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. \\
<br>
To use in your own project, examine the code.
24 changes: 24 additions & 0 deletions User Hash Generator/hash.py
Original file line number Diff line number Diff line change
@@ -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