详情描述:
我需要做游戏内登陆和论坛的对接,想使用hash对比
后端PHP
<?php
$myData=mysqli_connect( "localhost" ,"root" ,"" );//localhost本地服务器 登陆账户为root 密码为空
if ( mysqli_connect_errno())
{
echo "eron";
return;
}
// 选择数据库
mysqli_query($myData,"set names utf8") ;
mysqli_select_db($myData ,"Cool_yt_rgb" );//服务器数据库名字cool_yt_rgb
// 寻
$userID = $_POST['usernamePost'];//$_POST 后面的名字是在unity里面需要调用的
$userPWD = $_POST['passwordPost'];
//从cool_yt_rgb数据库建立的表中选择userinfo表的username和passport
$sql = "SELECT username FROM userinfo where username='".$userID."' and password ='".$userPWD."' ";
$result = mysqli_query($myData,$sql)or die("<br>SQL error!<br/>");
$num_results = mysqli_num_rows($result);
echo $num_results;
?>
前端C#(unity)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LoginURL : MonoBehaviour
{
public InputField userNameField;//登陆用户名
public InputField passWordField;//登录密码
public Text feedbackmsg;//实时返回状态文字
string LoginsURL = "http://localhost/cool_yt_rgb/LoginURL.php";//服务器连接
public void isLoad()
{
string idText = userNameField.text;
string pwdText = passWordField.text;
StartCoroutine(LoginToDB(idText, pwdText));
}
IEnumerator LoginToDB (string username, string password)
{
WWWForm form = new WWWForm();
form.AddField("usernamePost", username);
form.AddField("passwordPost", password);
WWW www = new WWW(LoginsURL, form);
yield return www;
if (www.text == "1")
{
Application.LoadLevel("111");
}
else
{
feedbackmsg.CrossFadeAlpha(100f, 0f, false);
feedbackmsg.color = Color.red;
feedbackmsg.text = "Login Error";
}
}
}
这是目前的代码,需要添加一个hash对比的模块在前端代码获取到password后,对比前