PHP登录注册(密码加密)

根据基本教程整理下的代码,代码目录如下(php小白,勿喷,小白共勉)

PHP登录注册(密码加密)_第1张图片

连接数据库php代码(conndb.php)

connect_error) {
    	die("连接失败: " . $conn->connect_error);
	}

?>

注册html界面(register.html)

登录名:
密码:
真实名字:
联系号码:
地址:
头像:

注册功能php代码(reigter.php)

console.log($hashpwd)";
	
	$truename = $_POST['truename'];
	$phone = $_POST['phone'];
	$address = $_POST['address'];
	$imgpath = $_POST['imgpath'];
	
	//获取当前时间
//	$time = date("Y/m/d h:i:sa");
//	$time = date("Y-m-d h:i:sa");
//	$begintime = $time;
//	$changetime = $time;
	
//	判断是否已经存在将要注册的用户名
	$sqlsearch = "select * from user where username='$username'";
	$seresult = $conn->query($sqlsearch);
	if($seresult->num_rows>0){
		echo "该用户名已经存在,请输入其他用户名";
		header("Location:../register.html");
	}else{
		echo "没有该用户信息";
		$sqlinsert = "INSERT INTO user (username, password, truename, phone, address, imgpath) VALUES ('$username','$hashpwd','$truename','$phone','$address','$imgpath')";
		if ($conn->query($sqlinsert) === TRUE) {
    		echo "新记录插入成功";
    		header("Location:../login.html");
		} else {
    		echo "出错,重新注册 " . $sql . "
" . $conn->error; header("Location:../register.html"); } } ?>

登录界面html(login.html)




	
		
		登录
		
	

	
		
		
登录名:
密码:

注册功能php代码(login.php)

alert('用户名密码不能为空'); history.go(-1);";
//		}else{
//			$result = mysqli_query($conn, $sqllogin);
//			$num = mysqli_num_rows($result);
//			if($num){
//				$row = mysqli_fetch_array($result, MYSQLI_NUM);
////				显示登录的用户名
////				echo $row[0];
////				跳转到主界面
//				header("Location:../index.html");
//			}else{
//				echo "";
//			}
//		}
		
		
		if($username == "" || $password == ""){
			echo "";
		}else{
//			获取数据库密码hash值
			$userpwd = "select * from user where username = '$username'";
			$resultpwd = $conn->query($userpwd);
			$pwd = mysqli_fetch_array($resultpwd);
//			echo $pwd['password'] . "
"; $hashpwd = $pwd['password']; // $hash = '$2y$10$5pvJcqeVIRTLPNMaesMT5OSr3vDFcehvV6pm8kZsIHJ34UBysFo/m'; if (password_verify($password, $hashpwd)) { echo '密码正确'; header("Location:../index.html"); } else { echo '密码错误'; echo ""; } } } else { echo ""; } ?>

 

 

 

你可能感兴趣的:(php)