ChandimaPrabath commited on
Commit
07c16c1
·
1 Parent(s): cfb5a7e

num user id

Browse files
Files changed (2) hide show
  1. generate-userid.py +26 -0
  2. main.py +26 -1
generate-userid.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import uuid
2
+
3
+ def generate_numeric_user_id(length=16):
4
+ """
5
+ Generates a numeric user ID with the specified length.
6
+
7
+ Args:
8
+ length: The desired length of the user ID.
9
+
10
+ Returns:
11
+ A string representing the numeric user ID.
12
+ """
13
+ # Generate a random UUID
14
+ uuid_str = str(uuid.uuid4()).replace('-', '')
15
+
16
+ # Convert the UUID to an integer
17
+ uuid_int = int(uuid_str, 16)
18
+
19
+ # Generate a numeric ID with the specified length
20
+ numeric_id = str(uuid_int)[-length:]
21
+
22
+ return numeric_id
23
+
24
+ # Generate and print a numeric user ID
25
+ user_id = generate_numeric_user_id()
26
+ print(f"Generated User ID: {user_id}")
main.py CHANGED
@@ -72,6 +72,31 @@ class UpdateUserRequest(BaseModel):
72
  class UpdateAccessLevelRequest(BaseModel):
73
  access_level: str
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  # Utility functions
76
  def hash_password(password: str) -> str:
77
  return hashlib.sha256(password.encode()).hexdigest()
@@ -121,7 +146,7 @@ async def signup(request: SignupRequest):
121
  )
122
 
123
  user_data = {
124
- "user_id": str(uuid.uuid4()),
125
  "username": request.username,
126
  "password": hash_password(request.password),
127
  "email": request.email,
 
72
  class UpdateAccessLevelRequest(BaseModel):
73
  access_level: str
74
 
75
+ def generate_numeric_user_id(length=10):
76
+ """
77
+ Generates a numeric user ID with the specified length.
78
+
79
+ Args:
80
+ length: The desired length of the user ID.
81
+
82
+ Returns:
83
+ A string representing the numeric user ID.
84
+ """
85
+ # Generate a random UUID
86
+ uuid_str = str(uuid.uuid4()).replace('-', '')
87
+
88
+ # Convert the UUID to an integer
89
+ uuid_int = int(uuid_str, 16)
90
+
91
+ # Generate a numeric ID with the specified length
92
+ numeric_id = str(uuid_int)[-length:]
93
+
94
+ return numeric_id
95
+
96
+ # Generate and print a numeric user ID
97
+ user_id = generate_numeric_user_id()
98
+ print(f"Generated User ID: {user_id}")
99
+
100
  # Utility functions
101
  def hash_password(password: str) -> str:
102
  return hashlib.sha256(password.encode()).hexdigest()
 
146
  )
147
 
148
  user_data = {
149
+ "user_id": int(generate_numeric_user_id(length=16)),
150
  "username": request.username,
151
  "password": hash_password(request.password),
152
  "email": request.email,