Skip to content

Commit 8bdc5a5

Browse files
authored
Merge pull request larymak#50 from urtuba/main
Adding user hash generator
2 parents f7836d5 + abacf89 commit 8bdc5a5

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

User Hash Generator/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# User Hash Generator
2+
3+
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.
4+
5+
## Getting Started
6+
7+
To demonstrate generator, a working terminal program is integrated. To try, type in terminal:
8+
9+
`$ python3 hash.py`
10+
11+
Notice: 'python3' keyword may be 'py' or 'python' for your system. \\
12+
<br>
13+
To use in your own project, examine the code.

User Hash Generator/hash.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from time import time
2+
from random import randint
3+
4+
def user_hash_generator():
5+
n = 1
6+
while True:
7+
timestamp = int(time()*1000)
8+
hash_string = hex(hash((timestamp/(randint(1, 250)+n))
9+
* (randint(1, 10)*5*n)))[2:14]
10+
n += 1
11+
yield hash_string
12+
13+
if __name__ == '__main__':
14+
print('Generator will create a random hash when you press only Enter.\
15+
\nTo exit, press any other button then Enter.')
16+
17+
hasher = user_hash_generator()
18+
while True:
19+
ch = input()
20+
if ch == '':
21+
print(next(hasher))
22+
else:
23+
print('Terminated')
24+
break

0 commit comments

Comments
 (0)