forked from Mrinank-Bhowmick/python-beginner-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathotpGen.py
More file actions
72 lines (63 loc) · 2.1 KB
/
otpGen.py
File metadata and controls
72 lines (63 loc) · 2.1 KB
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
import random
# s_char for small letters
s_char = "abcdefghijklmnopqrstuvwxyz"
# b_char for capital letters
b_char = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
# d_char for digits
d_char = "123456789"
class Otp:
def __init__(self, len):
self.len = len
# this method generate number otp
@property
def digits(self):
num = 0
result = []
while num < self.len:
rand_choice = "".join(random.choices(d_char, k=self.len)[0:1])
result.append(rand_choice)
num += 1
value = "".join(result)
return value
# this method generate number and capital letters otp
@property
def bd_digits(self):
num = 0
result = []
while num < self.len:
b_choice = "".join(random.choices(b_char, k=self.len)[0:1])
d_choice = "".join(random.choices(d_char, k=self.len)[0:1])
result.append(b_choice)
result.append(d_choice)
num += 1
value = "".join(result[0 : self.len])
return value
# this method generate number and small letters otp
@property
def sd_digits(self):
num = 0
result = []
while num < self.len:
s_choice = "".join(random.choices(s_char, k=self.len)[0:1])
d_choice = "".join(random.choices(d_char, k=self.len)[0:1])
result.append(s_choice)
result.append(d_choice)
num += 1
value = "".join(result[0 : self.len])
return value
# this method generate both small, capital letters and number otp all together
@property
def sbd_digits(self):
num = 0
result = []
while num < self.len:
s_choice = "".join(random.choices(s_char, k=self.len)[0:1])
b_choice = "".join(random.choices(b_char, k=self.len)[0:1])
d_choice = "".join(random.choices(d_char, k=self.len)[0:1])
result.append(s_choice)
result.append(b_choice)
result.append(d_choice)
num += 1
value = "".join(result[0 : self.len])
return value
print("OTP:" + Otp(10).digits)