-
Notifications
You must be signed in to change notification settings - Fork 2
/
login.php
56 lines (46 loc) · 1.65 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/* Start up our PHP sessions. */
session_start();
/* Include our configuration file. */
include __DIR__ . '/configuration.php';
/* Include the Composer autoloader. */
require_once __DIR__ . '/vendor/autoload.php';
/**
* We'll be using the PHP Composer package php-wowemu-auth from Laizerox.
* URL: https://github.com/Laizerox/php-wowemu-auth
*/
use Laizerox\Wowemu\SRP\UserClient;
/**
* Create a connection to the MySQL/MariaDB server using values
* defined in the configuration.php file.
*/
$db = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE_NAME);
/* Function to get values from MySQL. */
function getMySQLResult($query) {
global $db;
return $db->query($query)->fetch_object();
}
/* If the form has been submitted, process it. */
if (isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
/* Get the salt and verifier from realmd.account for the user. */
$query = "SELECT s, v FROM account WHERE username = '$username'";
$result = getMySQLResult($query);
$saltFromDatabase = $result->s;
$verifierFromDatabase = strtoupper($result->v);
/* Setup your client and verifier values. */
$client = new UserClient($username, $saltFromDatabase);
$verifier = strtoupper($client->generateVerifier($password));
/* Compare $verifierFromDatabase and $verifier. */
if ($verifierFromDatabase === $verifier) {
/**
* Do login stuff here, like setting cookies/sessions...
*/
} else {
/**
* Do whatever you wanna do when the login has failed,
* send a failure message, redirect them to another page, etc...
*/
}
}