nagasurendra commited on
Commit
0279e41
·
verified ·
1 Parent(s): 4ee4ce0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -10,23 +10,37 @@ sf = Salesforce(username='[email protected]',
10
  security_token='z7Wvk6mys7n8XjqbYKf3bwBh7')
11
 
12
 
13
- # Hash the password before saving
 
14
  def hash_password(password):
15
  return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
16
 
17
- # Verify hashed password
18
  def verify_password(plain_password, hashed_password):
19
  return bcrypt.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8'))
20
 
21
- # Signup function
22
  def signup(name, email, phone, password):
23
  try:
24
- hashed_password = hash_password(password) # Encrypt the password
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  sf.User_Login__c.create({
26
  'Name__c': name.strip(),
27
- 'Email__c': email.strip(),
28
  'Phone__c': phone.strip(),
29
- 'Password3__c': hashed_password # Store the hashed password
30
  })
31
  return "Signup successful! You can now login."
32
  except Exception as e:
 
10
  security_token='z7Wvk6mys7n8XjqbYKf3bwBh7')
11
 
12
 
13
+
14
+ # Function to Hash Password
15
  def hash_password(password):
16
  return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
17
 
18
+ # Function to Verify Password
19
  def verify_password(plain_password, hashed_password):
20
  return bcrypt.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8'))
21
 
22
+ # Signup function with email validation
23
  def signup(name, email, phone, password):
24
  try:
25
+ email = email.strip()
26
+
27
+ # Check if the email already exists in Salesforce
28
+ query = f"SELECT Id FROM User_Login__c WHERE Email__c = '{email}'"
29
+ result = sf.query(query)
30
+
31
+ if len(result['records']) > 0:
32
+ # Email already exists
33
+ return "Email already exists! Please use a different email."
34
+
35
+ # Hash the password
36
+ hashed_password = hash_password(password)
37
+
38
+ # Create the new user record
39
  sf.User_Login__c.create({
40
  'Name__c': name.strip(),
41
+ 'Email__c': email,
42
  'Phone__c': phone.strip(),
43
+ 'Password3__c': hashed_password # Use Password3__c field for hashed passwords
44
  })
45
  return "Signup successful! You can now login."
46
  except Exception as e: