创建一个类,在php中随机生成用户名和密码

时间:2013-08-01 10:14:58

标签: php random

我是PHP的初学者,但我有一个项目,我正在研究,我想创建一个类来生成用户名和密码代码并将其保存在数据库表中。 代码搞砸了。有人帮忙吗?

 public function generateCode() // Methode to generate username and password and display them
 {
 $data = array(); // create an array to store username and password generated

  $code_usr = rand(54000000,58000000);
 $this->_username = 'KU'.$code_usr;

 $code_pwd = rand(54000000,58000000);
 $this->_password = $code_pwd;

 $request = $db->query('SELECT username, password FROM user');

 $users = $request->fetch(PDO::FETCH_ASSOC);



for($data['username']) = this->_username;
 $data['password'] = this->_password;





 echo 'User '.$this->_username;
 echo '<br/>';
 echo 'Password '. $this->_password;

 }
public function saveCode() // Methode to save username and password




public function listCode() // Methode to list username and password form the database table
}
$code = new CodeGenerator;
$code->generateCode();
public function generateCode() // Methode to generate username and password and display them { $data = array(); // create an array to store username and password generated $code_usr = rand(54000000,58000000); $this->_username = 'KU'.$code_usr; $code_pwd = rand(54000000,58000000); $this->_password = $code_pwd; $request = $db->query('SELECT username, password FROM user'); $users = $request->fetch(PDO::FETCH_ASSOC); for($data['username']) = this->_username; $data['password'] = this->_password; echo 'User '.$this->_username; echo '<br/>'; echo 'Password '. $this->_password; } public function saveCode() // Methode to save username and password public function listCode() // Methode to list username and password form the database table } $code = new CodeGenerator; $code->generateCode();

1 个答案:

答案 0 :(得分:0)

结帐此链接generate username and password

希望它能解决您的问题