Randomness::blowfishSalt() generates a salt to use with crypt(). Let's say you have an AR model class User for the user records in your DB and a form model instance $form holding the username and password etc. of the new user. The controller action where you register new users might include:
$user = new User;
$user->email = $form->email;
$user->password = crypt($form->password, Randomness::blowfishSalt());
if ($user->save()) {
...
}
To authenticate (refer to the authenticate method in protected/components/UserIdentity.php of a fresh yiic webapp, see also theauth topic in the Yii Guide):
public function authenticate()
{
$record = User::model()->findByAttributes(array('username' => $this->username));
if ($record === null) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else if ($record->password !== crypt($this->password, $record->password)) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$this->_id = $record->id;
$this->setState('title', $record->title);
$this->errorCode = self::ERROR_NONE;
}
return !$this->errorCode;
}--
--
Grupo PHPBA
http://groups.google.com.br/group/phpba?hl=pt-BR?hl=pt-BR
---
Você está recebendo esta mensagem porque se inscreveu no grupo "PHPBA" dos Grupos do Google.
Para cancelar a inscrição neste grupo e parar de receber seus e-mails, envie um e-mail para phpba+un...@googlegroups.com.
Para obter mais opções, acesse https://groups.google.com/groups/opt_out.
Esta mensagem, incluindo seus anexos, tem caráter confidencial e seu conteúdo é restrito ao destinatário da mensagem. Caso você tenha recebido esta mensagem por engano, queira por favor, retorná-la ao destinatário e apagá-la de seus arquivos. Qualquer uso não autorizado, replicação ou disseminação desta mensagem ou parte dela é expressamente proibido. O autor não é responsável pelo conteúdo ou a veracidade desta informação.
This message, including its annexes, has confidence and their content is restricted to recipiente of the message . If you have received this message in error, please, return it to the recipiente and delete it from your files. Any unauthorized use, dissemination or replication of part or this message is strictly prohibited. The author is not responsible for the content or the veracity of this information
include(Randomness.php): failed to open stream: No such file or directory
E:\D\Dropbox\htdocs\yii\framework\YiiBase.php(421)
409 { 410 include($classFile); 411 if(YII_DEBUG && basename(realpath($classFile))!==$className.'.php') 412 throw new CException(Yii::t('yii','Class name "{class}" does not match class file "{file}".', array( 413 '{class}'=>$className, 414 '{file}'=>$classFile, 415 ))); 416 break; 417 } 418 } 419 } 420 else 421 include($className.'.php'); 422 } 423 else // class name with namespace in PHP 5.3 424 { 425 $namespace=str_replace('\\','.',ltrim($className,'\\')); 426 if(($path=self::getPathOfAlias($namespace))!==false) 427 include($path.'.php'); 428 else 429 return false; 430 } 431 return class_exists($className,false) || interface_exists($className,false); 432 } 433 return true;
| #0 |
+ E:\D\Dropbox\htdocs\yii\framework\YiiBase.php(421): YiiBase::autoload() |
| #1 |
unknown(0): YiiBase::autoload("Randomness")
|
| #2 |
– E:\D\Dropbox\htdocs\ni_protected\models\User.php(120): spl_autoload_call("Randomness")115 public function beforeSave() { 116 if (!empty($this->password)){ 117 //$context = hash_init('sha256', HASH_HMAC, MYSALT); 118 //hash_update($context, $this->password); 119 //$this->password = hash_final($context);; 120 $this->password = crypt($this->password, Randomness::blowfishSalt()); 121 //$this->password = md5($this->password); 122 } 123 return true; 124 } 125 } |
| #3 |
+ E:\D\Dropbox\htdocs\yii\framework\db\ar\CActiveRecord.php(1017): User->beforeSave() |
| #4 |
+ E:\D\Dropbox\htdocs\yii\framework\db\ar\CActiveRecord.php(795): CActiveRecord->insert(null) |
| #5 |
– E:\D\Dropbox\htdocs\ni_protected\controllers\UserController.php(73): CActiveRecord->save()68 // $this->performAjaxValidation($model); 69 70 if(isset($_POST['User'])) 71 { 72 $model->attributes=$_POST['User']; 73 if($model->save()) 74 $this->redirect(array('view','id'=>$model->id)); 75 } 76 77 $this->render('create',array( 78 'model'=>$model, |
| #6 |
+ E:\D\Dropbox\htdocs\yii\framework\web\actions\CInlineAction.php(49): UserController->actionCreate() |
| #7 |
+ E:\D\Dropbox\htdocs\yii\framework\web\CController.php(308): CInlineAction->runWithParams(array()) |
| #8 |
+ E:\D\Dropbox\htdocs\yii\framework\web\filters\CFilterChain.php(133): CController->runAction(CInlineAction) |
| #9 |
+ E:\D\Dropbox\htdocs\yii\framework\web\filters\CFilter.php(40): CFilterChain->run() |
| #10 |
+ E:\D\Dropbox\htdocs\yii\framework\web\CController.php(1145): CFilter->filter(CFilterChain) |
| #11 |
+ E:\D\Dropbox\htdocs\yii\framework\web\filters\CInlineFilter.php(58): CController->filterAccessControl(CFilterChain) |
| #12 |
+ E:\D\Dropbox\htdocs\yii\framework\web\filters\CFilterChain.php(130): CInlineFilter->filter(CFilterChain) |
| #13 |
+ E:\D\Dropbox\htdocs\yii\framework\web\CController.php(291): CFilterChain->run() |
| #14 |
+ E:\D\Dropbox\htdocs\yii\framework\web\CController.php(265): CController->runActionWithFilters(CInlineAction, array("accessControl", "postOnly + delete")) |
| #15 |
+ E:\D\Dropbox\htdocs\yii\framework\web\CWebApplication.php(282): CController->run("create") |
| #16 |
+ E:\D\Dropbox\htdocs\yii\framework\web\CWebApplication.php(141): CWebApplication->runController("user/create") |
| #17 |
+ E:\D\Dropbox\htdocs\yii\framework\base\CApplication.php(169): CWebApplication->processRequest() |
| #18 |
– E:\D\Dropbox\htdocs\ni\index.php(13): CApplication->run()08 defined('YII_DEBUG') or define('YII_DEBUG',true); 09 // specify how many levels of call stack should be shown in each log message 10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3); 11 require_once 'config.php'; 12 require_once($yii); 13 Yii::createWebApplication($config)->run(); |
| Application Log | ||||
|---|---|---|---|---|
| Timestamp | Level | Category | Message | |
| 20:06:19.856573 | trace | system.CModule | Loading "log" application component in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:19.858998 | trace | system.CModule | Loading "request" application component in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:19.861666 | trace | system.CModule | Loading "urlManager" application component in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:19.869033 | trace | system.web.filters.CFilterChain | Running filter UserController.filteraccessControl() in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:19.869827 | trace | system.CModule | Loading "user" application component in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:19.871417 | trace | system.CModule | Loading "session" application component in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:19.879565 | trace | system.CModule | Loading "db" application component in E:\D\Dropbox\htdocs\ni_protected\controllers\UserController.php (65) in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:19.880945 | trace | system.db.CDbConnection | Opening DB connection in E:\D\Dropbox\htdocs\ni_protected\controllers\UserController.php (65) in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:20.896756 | trace | system.db.CDbCommand | Querying SQL: SHOW FULL COLUMNS FROM `user` in E:\D\Dropbox\htdocs\ni_protected\controllers\UserController.php (65) in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:20.904453 | trace | system.db.CDbCommand | Querying SQL: SHOW CREATE TABLE `user` in E:\D\Dropbox\htdocs\ni_protected\controllers\UserController.php (65) in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:20.915282 | trace | system.db.ar.CActiveRecord | User.exists() in E:\D\Dropbox\htdocs\ni_protected\controllers\UserController.php (73) in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:20.918867 | trace | system.db.CDbCommand | Querying SQL: SELECT 1 FROM `user` `t` WHERE `t`.`email`=:ycp0 LIMIT 1 in E:\D\Dropbox\htdocs\ni_protected\controllers\UserController.php (73) in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:20.940645 | error | php | include(Randomness.php): failed to open stream: No such file or directory (E:\D\Dropbox\htdocs\yii\framework\YiiBase.php:421) Stack trace: #0 E:\D\Dropbox\htdocs\ni_protected\models\User.php(120): spl_autoload_call() #1 E:\D\Dropbox\htdocs\yii\framework\db\ar\CActiveRecord.php(1017): User->beforeSave() #2 E:\D\Dropbox\htdocs\yii\framework\db\ar\CActiveRecord.php(795): User->insert() #3 E:\D\Dropbox\htdocs\ni_protected\controllers\UserController.php(73): User->save() #4 E:\D\Dropbox\htdocs\yii\framework\web\actions\CInlineAction.php(49): UserController->actionCreate() #5 E:\D\Dropbox\htdocs\yii\framework\web\CController.php(308): CInlineAction->runWithParams() #6 E:\D\Dropbox\htdocs\yii\framework\web\filters\CFilterChain.php(133): UserController->runAction() #7 E:\D\Dropbox\htdocs\yii\framework\web\filters\CFilter.php(40): CFilterChain->run() #8 E:\D\Dropbox\htdocs\yii\framework\web\CController.php(1145): CAccessControlFilter->filter() #9 E:\D\Dropbox\htdocs\yii\framework\web\filters\CInlineFilter.php(58): UserController->filterAccessControl() #10 E:\D\Dropbox\htdocs\yii\framework\web\filters\CFilterChain.php(130): CInlineFilter->filter() #11 E:\D\Dropbox\htdocs\yii\framework\web\CController.php(291): CFilterChain->run() #12 E:\D\Dropbox\htdocs\yii\framework\web\CController.php(265): UserController->runActionWithFilters() #13 E:\D\Dropbox\htdocs\yii\framework\web\CWebApplication.php(282): UserController->run() #14 E:\D\Dropbox\htdocs\yii\framework\web\CWebApplication.php(141): CWebApplication->runController() #15 E:\D\Dropbox\htdocs\yii\framework\base\CApplication.php(169): CWebApplication->processRequest() #16 E:\D\Dropbox\htdocs\ni\index.php(13): CWebApplication->run() REQUEST_URI=/ni/user/create in E:\D\Dropbox\htdocs\ni_protected\models\User.php (120) in E:\D\Dropbox\htdocs\ni_protected\controllers\UserController.php (73) in E:\D\Dropbox\htdocs\ni\index.php (13) | |
| 20:06:20.955554 | trace | system.CModule | Loading "errorHandler" application component in E:\D\Dropbox\htdocs\ni_protected\models\User.php (120) in E:\D\Dropbox\htdocs\ni_protected\controllers\UserController.php (73) in E:\D\Dropbox\htdocs\ni\index.php (13) | |
Só importa sob demanda
--------------------------------------------------------+55 71 3314-4819 / 8887-5807 / 9192-2161Esta mensagem, incluindo seus anexos, tem caráter confidencial e seu conteúdo é restrito ao destinatário da mensagem. Caso você tenha recebido esta mensagem por engano, queira por favor, retorná-la ao destinatário e apagá-la de seus arquivos. Qualquer uso não autorizado, replicação ou disseminação desta mensagem ou parte dela é expressamente proibido. O autor não é responsável pelo conteúdo ou a veracidade desta informação.
This message, including its annexes, has confidence and their content is restricted to recipiente of the message . If you have received this message in error, please, return it to the recipiente and delete it from your files. Any unauthorized use, dissemination or replication of part or this message is strictly prohibited. The author is not responsible for the content or the veracity of this information
--
--
Grupo PHPBA
http://groups.google.com.br/group/phpba?hl=pt-BR?hl=pt-BR
---
Você está recebendo esta mensagem porque se inscreveu no grupo "PHPBA" dos Grupos do Google.
Para cancelar a inscrição neste grupo e parar de receber seus e-mails, envie um e-mail para phpba+un...@googlegroups.com.
Para obter mais opções, acesse https://groups.google.com/groups/opt_out.