Yii Framework Forum: password encryption - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

password encryption why in User model and not in actionCreate

#1 User is offline   caramelon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 19-January 11
  • Location:Neandertal

Posted 10 August 2011 - 05:25 AM

Hi everyone,

In page 159, password encryption functionality is added using CActiveRecord::afterValidate() method. I'm pondering about the alternative way of implementing encryption in UserController::actionCreate().

Besides the educational purpose of showing us the afterValidate() method, what are the pros and cons of both places?

Regards,
0

#2 User is offline   Ivica 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 317
  • Joined: 25-May 11

Posted 10 August 2011 - 07:42 AM

Well, after validate is good place, because you crypt after it passed all validations. Also I like idea of keeping everything related to model in model so this is another reason.

Off course you could encrypt your password in controller, after it pass(if) validation, but I like more solution explained in book.
Zurmo: Yii Powered Open Source CRM
zurmo.org
0

#3 User is offline   Say_Ten 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 17-September 10

Posted 10 August 2011 - 09:05 AM

It makes sense that the encryption is performed within the model, as how the model encrypts it's passwords is something for the model to encapsulate and not a controller, which is primarily about routing data, to handle. So, for example you may wish to create users in a few places and not have to add the logic to hash the password in each of those places. Might be worth just reading about MVC architecture to remind yourself about the responsibilities of the Models, Views and Controllers.
0

#4 User is offline   salman 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 30-August 10

Posted 30 July 2012 - 05:49 AM

getting this

Use of undefined constant value - assumed 'value'
Good Programming is 99% Sweet and 1% Coffee
0

#5 User is offline   Jimmy Henry rugal 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 28-September 12
  • Location:Colorado

Posted 28 September 2012 - 10:10 AM

While it's an energetic romp, there is more slapstick humor than wit at work here
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users