New topic: 

My SQL Encode/Decode Functions

<http://forums.realsoftware.com/viewtopic.php?t=37387>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        paul3252          Post subject: My SQL Encode/Decode 
FunctionsPosted: Wed Feb 02, 2011 11:12 am                         
Joined: Mon Jan 11, 2010 11:56 am
Posts: 60
Location: United Kingdom                I want to read an 'encoded' field into 
RS from a database using the MySQL encode and decode functions

Decode/Encode('text to encode or decode', 'phrase')

Creating a new record, no problem, (sqlify is a function found on the board 
that makes text sql friendly)

  Code:sqli="INSERT INTO tbl_users(User_Name, User_Initials, Supervisor, 
Power_User, Email, tbl_users.`Password`, Deleted) VALUES ('"
  
sqli=sqli+sqlify(fldUserName.text)+"','"+SQLify(fldUserInitials.text)+"','"+str(sup)+"','"+str(pow)+"','"+SQLify(fldEmailAddress.text)+"',"
  sqli=sqli+"ENCODE('"+fldPassword.text+"','passphrase'),'0')"

This creates a new record with a properly encoded password field.

If I then want to 'edit a user' how do I then get the password 'decoded' back 
into the control. I thought this may work but it seems to crash RS. Any advice 
would be appreciated.

  Code:sql = "select User_ID, User_Name, User_Initials, Supervisor, Power_User, 
Email, Decode(tbl_users.Password,'passphrase') from tbl_users where User_Name 
LIKE BINARY '"+ combo_username.text+"'"
  
  rs=db.SQLSelect(sql)
  if rs<>nil then
  fldUserInitials.Enabled=true
  fldPowerUser.Enabled=true
  fldSupervisor.Enabled=true
  fldEmailAddress.enabled=true
  fldPassword.enabled=true
  fldUserInitials.text=rs.field("User_Initials")
  fldsupervisor.value=(rs.field("Supervisor").BooleanValue)
  fldPowerUser.value=(rs.field("Power_User").BooleanValue)
  fldEmailAddress.text=rs.field("Email")
  fldPassword.text=rs.field("Password") 
  btnsave.enabled=true
  editmode=true
  else
  db_error
  end if

No error is thrown by my db_error function and the 'if then' runs fine.      
_________________
Paul
Realstudio 2010r4
Windows XP, Windows 7
  
                             Top                 jefftullin          Post 
subject: Re: My SQL Encode/Decode FunctionsPosted: Wed Feb 02, 2011 11:18 am    
                             
Joined: Wed Nov 15, 2006 3:50 pm
Posts: 2106
Location: England                Well, I cant see where you are decoding it 
before displaying it.
Is it that simple?

But a general note:
Quote:If I then want to 'edit a user' how do I then get the password 'decoded' 
back into the control. I thought this may work but it seems to crash RS. Any 
advice would be appreciated.

Don't decode and display an existing password.
Far safer is to accept a password from someone, encode it, and check to see if 
the encoded version matches the contents of the database.
That way, the decoded version isn't available unless you know it. One way 
encryption.

You dont really need to know what it is , just that the user has entered it 
correctly.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to