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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -1,49 +1,59 @@
 
 
 
 
1
  import gradio as gr
2
  from simple_salesforce import Salesforce
3
-
4
  # Salesforce Connection
5
  sf = Salesforce(username='[email protected]',
6
  password='Lavanyanaga@123',
7
  security_token='z7Wvk6mys7n8XjqbYKf3bwBh7')
8
 
9
 
 
 
 
 
 
 
 
10
 
11
- # Signup Function
12
  def signup(name, email, phone, password):
13
  try:
 
14
  sf.User_Login__c.create({
15
  'Name__c': name.strip(),
16
  'Email__c': email.strip(),
17
  'Phone__c': phone.strip(),
18
- 'Password2__c': password.strip() # Use the new field Password2__c
19
  })
20
  return "Signup successful! You can now login."
21
  except Exception as e:
22
  return f"Error during signup: {str(e)}"
23
 
24
- # Login Function
25
  def login(email, password):
26
  try:
27
  email = email.strip()
28
  password = password.strip()
29
 
30
  # Query Salesforce for user details
31
- query = f"SELECT Name__c, Email__c, Phone__c, Password2__c FROM User_Login__c WHERE Email__c = '{email}'"
32
  result = sf.query(query)
33
 
34
  if len(result['records']) == 0:
35
- print(f"No user found with email: {email}")
36
  return "Invalid email or password.", None, None, None
37
 
38
  user = result['records'][0]
39
- stored_password = user['Password2__c']
40
 
41
  print(f"Entered Email: {email}")
42
  print(f"Entered Password: {password}")
43
- print(f"Stored Password: {stored_password}")
44
 
45
- # Compare plain-text passwords
46
- if password == stored_password:
47
  print("Password matched!")
48
  return "Login successful!", user['Name__c'], user['Email__c'], user['Phone__c']
49
  else:
 
1
+
2
+
3
+
4
+ import bcrypt
5
  import gradio as gr
6
  from simple_salesforce import Salesforce
 
7
  # Salesforce Connection
8
  sf = Salesforce(username='[email protected]',
9
  password='Lavanyanaga@123',
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:
33
  return f"Error during signup: {str(e)}"
34
 
35
+ # Login function
36
  def login(email, password):
37
  try:
38
  email = email.strip()
39
  password = password.strip()
40
 
41
  # Query Salesforce for user details
42
+ query = f"SELECT Name__c, Email__c, Phone__c, Password3__c FROM User_Login__c WHERE Email__c = '{email}'"
43
  result = sf.query(query)
44
 
45
  if len(result['records']) == 0:
 
46
  return "Invalid email or password.", None, None, None
47
 
48
  user = result['records'][0]
49
+ stored_password = user['Password3__c']
50
 
51
  print(f"Entered Email: {email}")
52
  print(f"Entered Password: {password}")
53
+ print(f"Stored Hashed Password: {stored_password}")
54
 
55
+ # Verify the entered password with the stored hash
56
+ if verify_password(password, stored_password):
57
  print("Password matched!")
58
  return "Login successful!", user['Name__c'], user['Email__c'], user['Phone__c']
59
  else: