17488 Posts in 4473 Topics by 1978 members
| Go to End | Next > | |
| Author | Topic: | 2520 Views |
-
Encrypted Fields

3 April 2008 at 12:24am
Hi All,
Hoping someone can help me a with a little problem.
How can I get the users to fill in a varchar field and have it stored in a encrypted format in the database?
thanks.
-
Re: Encrypted Fields

3 April 2008 at 3:19am
Don't know if this is functional , but I found an EncryptField in the API ?
Did you try that ?
-
Re: Encrypted Fields

3 April 2008 at 12:50pm
thanks Fuzz
I will check it out and return back with my findings.
-
Re: Encrypted Fields

3 April 2008 at 9:29pm
EncyptField is just a deprecated duplicate of PasswordField.
To do what you've requested, you should define an onBeforeWrite() method on your DataObject.
This example will md5-encode the field "MyField".
function onBeforeWrite() {
if(!$this->ID || $this->changed['MyField']) {
$this->MyField = md5($this->MyField);
}
}Alternatively, if you need it to get encrypted straight away and not once the dataobject is written, you could define setMyField(). This is the function that is called when you go $obj->MyField = 'value';
function setMyField($value) {
$this->setField('MyField', md5($value));
} -
Re: Encrypted Fields

4 April 2008 at 1:06am
Ah...
As expected, SS offers an an elegant solution. ;-)
-
Re: Encrypted Fields

22 April 2008 at 3:51pm Last edited: 22 April 2008 4:10pm
Sam,
Your suggestion worked great, thanks.
My only problem now is I can't find where to decrypt the data for the Admin to view it.
If anyone has any advice I would be greatful.
thanks.
-
Re: Encrypted Fields

22 April 2008 at 4:31pm
Assuming you used the md5 function, you can't reverse it.
| 2520 Views | ||
| Go to Top | Next > |



