首页 > 解决方案 > 用户登录时PHP MYSQL,将密码作为变量插入到不同的数据库?

问题描述

我希望有权访问我的网站的用户能够在我的新网站上使用他们的登录凭据,而不必做任何事情,例如再次注册,所以我正在做的是,每当他们登录到我的旧网站时,这就是登录表格:

<?php

require_once(PROJECTS_PATH . '/path/to/Form.php');
class UserLogin extends Form {

var $focusFirst = 'email';

function __construct() {
    parent::__construct();
    $this->input('email')->required("Please enter your email (or 
login).")->label("Email (or login)")->width(40);
    $this->password('password')->required("Please enter your password.");
    $this->link('cancel', '/user/redirect', array("style" => "padding- 
right: 50px;"))->label('Cancel');
    $this->submit('login'); #, array('value' => 'Login'));
    require ('/path/to/scripts/updateUsers.php'); //This includes the script that creates a new user for my new site
}
}
?>

我尝试了很多不同的方法,但似乎没有成功。我能够从用户那里获取所有需要的信息,以便在我的数据库中为我的新站点创建一个新用户,但我可以'不让密码通过我想把它原始到我的 updateUsers 脚本中,在那个脚本中我正在散列它。

注意:我不能只将我的数据库用户表移动到我的新站点表,因为涉及到不同的散列。

我的 updateUsers 脚本:

<?php
$firstname = $user['first_name'];
$mail  = $user['email'];
$pw = 'TestPasswor'; //I'm doing this right not which works but I need the actual user's pw otherwise this is useless

include("/path/to/password.inc"); //for hashing the pw 
include("/path/to/bootstrap.inc");
$hashed_password = user_hash_password(trim($pw));

$query = sprintf("INSERT INTO test_db.users (name, pass, mail, status)
VALUES ('$firstname', '$hashed_password', '$mail', '1')",
mysql_real_escape_string($firstname),
mysql_real_escape_string($hashed_password),
mysql_real_escape_string($mail));

// Perform Query
$result = mysql_query($query);
?>

对不起,我知道这是一个很长的描述,但谢谢!

标签: phpmysqlparameterspasswords

解决方案


推荐阅读