Files
InternetRadio-Website/manage/php/session/register.php
T
2026-06-17 15:46:26 +02:00

69 lines
1.9 KiB
PHP

<?php
require('../../../inc/connect.php');
require('../../../inc/crypt.php');
$username = $_POST['username'];
$email = $_POST['email'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];
$device = $_POST['device'];
//Validate Device ID
if(strlen($device) != 6)
{
error("login", "Device ID invalid");
}
$sql = "SELECT `id` FROM `device` WHERE `dev_id`='" . $device . "' AND `user`=0";
$query = ExecQuery($mysqli, $sql);
if($query->num_rows < 1)
{
error("login", "Device ID invalid");
}
//Validate email
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
error("login", "Invalid email address");
}
$sql = "SELECT `id` FROM `user` WHERE `email`='" . $email . "' AND verified=1";
$query = ExecQuery($mysqli, $sql);
if($query->num_rows >= 1)
{
error("login", "Email address is already in use.");
}
//Validate username
$sql = "SELECT `id` FROM `user` WHERE `username`='" . $username . "'";
$query = ExecQuery($mysqli, $sql);
if($query->num_rows >= 1)
{
error("login", "Username is already in use.");
}
//Validate password
if($password1 != $password2)
{
error("login", "Passwords do not match");
}
$password_hash = password_hash($password1, PASSWORD_BCRYPT);
$code = $email . "~" . $device . "~";
$code .= RandomString(96 - strlen($code));
$code = str_rot13($code);
$sql = "INSERT INTO user (`username`, `password`, `email`, `code`) VALUES ('$username', '$password_hash', '$email', '$code')";
ExecQuery($mysqli, $sql);
$msg = "Hello " . $username . ",\n\n";
$msg .= "Please verify your LiPaccount by clicking the link below.\n";
$msg .= "<a href='http://lipa.kvewijk.nl/manage/php/session/verify.php?code=" . urlencode($code) . "'>Verify</a>";
sendMail($email, "Verify LiPaccount", $msg);
success("login", "An email has been sent to " . $email . " for verification");
?>