I tried looking around and I couldn't find anything. I want to hash the password on the registration page before it inserts into the database. I did some searching, and I found some hash related things for addValidator()
, but from my understanding, that is to validate an element, but I actually need to transform an element before inserting in the the database. How can I do this?
Asked
Active
Viewed 279 times
1

Aurelio De Rosa
- 21,856
- 8
- 48
- 71

Strawberry
- 66,024
- 56
- 149
- 197
2 Answers
1
You should do the hash in the controller, before you send the data to the model and after the form validation. Besides, this task should not be achieved by a validator and this is why you cannot find anyone who fits your need. Indeed it should be done by a filter. Anyway, there's no filter which achieve this goal too.
To hash the password, hence, you can use any built-in hash function of php as hash
, md5
, sha1
.

Aurelio De Rosa
- 21,856
- 8
- 48
- 71
-
Oh, this way, I don't know have to do anything to the form. Okay, fair enough. Upvote! – Strawberry Oct 16 '11 at 23:04
1
In conjunction with AurelioDeRosa's answer please read PHP's advice on hashing passwords. In short you shouldn't use hash
, md5
or sha1
to hash passwords. It is suggested that you use the built in crypt
function with the Blowfish
algorithm. See the link for an explanation.

Jonathan Spooner
- 7,682
- 2
- 34
- 41