1

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?

Aurelio De Rosa
  • 21,856
  • 8
  • 48
  • 71
Strawberry
  • 66,024
  • 56
  • 149
  • 197

2 Answers2

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
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