This repository has been archived by the owner on Dec 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
73 lines (58 loc) · 1.64 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import random
from string import ascii_letters
class OTPGenerator:
"""Generates OTP of alpha-numeric, numeric and character types."""
def __init__(self, length=5):
"""
Parameters
----------
length: int
Length of OTP to generate
"""
self.OTP_LENGTH = length
self.INT_START = 0
self.INT_END = 10
def generate_alpha_numeric_otp(self) -> str:
"""Generates alpha numeric otp
Returns
-------
:str
String of random alpha numeric characters.
"""
otp = ""
i = 0
while i < self.OTP_LENGTH:
result = random.randint(0, 2)
# if result is 0 them add a random letter else add a random digit
if result == 0:
otp += random.choice(ascii_letters)
else:
otp += str(random.randint(self.INT_START, self.INT_END))
i += 1
return otp
def generate_numeric_otp(self) -> str:
"""Generates numeric otp
Returns
-------
:str
String of random numeric characters.
"""
otp = ""
i = 0
while i < self.OTP_LENGTH:
otp += str(random.randint(self.INT_START, self.INT_END))
i += 1
return otp
def generate_alpha_otp(self) -> str:
"""Generates alphabetic otp
Returns
-------
:str
String of random alphabetic characters.
"""
otp = ""
i = 0
while i < self.OTP_LENGTH:
otp += random.choice(ascii_letters)
i += 1
return otp