【问题标题】:Android App User Authentication with Wordpress DB使用 Wordpress DB 进行 Android 应用用户身份验证
【发布时间】:2017-05-28 02:30:07
【问题描述】:

我需要帮助我使用 android 在我的 wordpress 网站上进行用户身份验证。我正在向我网站上的 PHP 文件发送包含登录信息(电子邮件和密码)的请求。在文件中,我有一个 SQL 语句,它应该给我来自wp-users 表的display_name。到目前为止这么好。我可以检查电子邮件地址,它工作正常,但是当我想在 wp-users 表中使用我的密码分配密码(在应用程序中输入)时,我遇到了一个大问题,因为数据库中的密码是散列的。我已经在哈希生成器中输入了我的密码,看看它是否相同,但我不是。你能帮帮我吗?

SQL:

SELECT display_name FROM wp_users WHERE user_email = "max-mustermann@web.de" AND user_pass = "Test1234!"

邮箱和密码只是一个例子,后面会用变量代替。

【问题讨论】:

  • 使用什么哈希算法对存储在您的数据库中的密码进行哈希处理?
  • 我不知道,但它是标准的 wordpress 算法

标签: php android sql wordpress


【解决方案1】:

这是我对这个问题的回答。这个答案告诉您如何使用 wp-users 表中存放的密码从变量中检查密码(在我的示例中登录以检查用户是否输入了正确的密码)。

<?php 
	include_once('wp-includes/class-phpass.php');
	include('wp-content/themes/storefront/db_connection.php'); //In my case I have a database connection php with my db login options
	$loginEmail = "your-email@here.com"; //You can replace it with a $_GET[] or $_POST[] variable
	$loginPassword = "yourpassword"	//*
	$hasher = new PasswordHash(8, TRUE);
	
	//Checking if the $loginPassword equals the password in the wp_users database in Wordpress
	$password_result = mysqli_query($conn, "SELECT user_pass FROM wp_users WHERE user_email = '$loginEmail'");
	if ($password_result->num_rows > 0) {
		while($row = $password_result->fetch_assoc()) {
			$hashPassword = $row["user_pass"];
		}
	} else {
		//echo some error if no result
	}
	if($hasher->CheckPassword($loginPassword, $hashPassword)) {
		//Send you $loginPassword to Wordpress hasher to check if they are the same
	} else {
		//do something if passwords don't match
	}
?>

【讨论】:

  • 如果对某人有帮助,请给我投票并将其标记为答案:)
猜你喜欢
  • 2014-02-07
  • 1970-01-01
  • 1970-01-01
  • 2014-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-11
相关资源
最近更新 更多