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.
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
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.
Don't know if this is functional , but I found an EncryptField in the API ?
Did you try that ?
thanks Fuzz
I will check it out and return back with my findings.
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));
}
Ah...
As expected, SS offers an an elegant solution. ;-)
that is fantastic.. thanks for the feedback.
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.
Assuming you used the md5 function, you can't reverse it.