我已经创建了一个带有密码字段的表单,用于在网站上注册。
new Zend_Form_Element_Password('password', array(
'required' => true,
'label' => $this->getView()->translate('createprofile_password'),
'filters' => array('StringTrim'),
'validators' => array(
new Zend_Validate_StringLength(array('min' => 6, 'max' => 20, 'encoding' => 'utf-8')),
),
'class' => "validate['required','length[6,20]']",
)),如何将其保存到数据库中?我试过这样的方法,但不起作用。密码未加密。
$profile = new Profile();
$entry = $profile->createEntry(array(
'firstname' => $requestPost['firstname'],
'lastname' => $requestPost['lastname'],
'email' => $requestPost['email'],
'password' => $requestPost['password'],
'published' => 1,
));
$profileId = $entry->save();发布于 2012-03-30 18:06:03
这是一个简单的示例:
$profile = new Profile();
$entry = $profile->createEntry(array(
'firstname' => $requestPost['firstname'],
'lastname' => $requestPost['lastname'],
'email' => $requestPost['email'],
//hash password using sha1 and a salt (returns 40 character string) .
//Save the salt reference somewhere so you can rebuilt the string to compare hashes for authentication.
//a salt is arbitrary data prepended or appended to the data being hashed
'password' => sha1($salt . $requestPost['password']),
'published' => 1,
));
$profileId = $entry->save();要在以后对密码进行身份验证,请重新构建并散列字符串:
//both hashes should match exactly
if (sha1($salt . $inputPassword) === $password)//$password form data store散列通常用于密码,因为它在资源上更容易使用,并且除了创建密码的人之外,没有人可以知道它。没有合理的方法来撤消加了盐的哈希。您所知道的就是输入的散列password+salt是否与保存的散列password+salt相同。
https://stackoverflow.com/questions/9925622
复制相似问题