我有一个简单的注册表单和使用 md5 加密和 salt 散列的密码,我收到一条错误消息,说“uni”字段不能为空,我假设这是因为我不确定如何添加将 $salt 放入表单中(它不是隐藏元素吗?就像 id 字段一样?)。我已经完成了以下模型:
public function addUser($first_name, $surname, $email, $username, $password, $salt, $age, $gender, $uni) {
$salt=substr(md5(mt_rand()),0,20);
$md5Password=md5($salt.$password);
$data = array(
'first_name' => $first_name,
'surname' => $surname,
'email' => $email,
'username' => $username,
'salt' => $salt,
'password' => $md5Password,
'age' => $age,
'gender' => $gender,
'uni' => $uni,
);
$this->insert($data);
}
这是表格:
<?php
class Application_Form_Register extends Zend_Form
{
public function init() {
$this->setName('register');
$id = new Zend_Form_Element_Hidden('id');
$id->addFilter('Int');
$first_name = new Zend_Form_Element_Text('first_name');
$first_name->setLabel('Firstname:')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$surname = new Zend_Form_Element_Text('surname');
$surname->setLabel('Surname:')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email:')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$username = new Zend_Form_Element_Text('username');
$username->setLabel('Username:')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$password = new Zend_Form_Element_Password('password');
$password->setLabel('Password:')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$salt = new Zend_Form_Element_Hidden('salt');
$age = new Zend_Form_Element_Text('age');
$age->setLabel('Age:')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$gender = new Zend_Form_Element_Text('gender');
$gender->setLabel('Gender:')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$uni = new Zend_Form_Element_Text('uni');
$uni->setLabel('University:')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setAttrib('id', 'submitbutton');
$this->addElements(array($id, $first_name, $surname, $email, $username, $password, $salt, $age, $gender, $uni, $submit));
}
}
谢谢
里克