prepare('SELECT password FROM ' . AUTHME_TABLE . ' WHERE username = ?'); $stmt->bind_param('s', $username); $stmt->execute(); $stmt->bind_result($password); if ($stmt->fetch()) { return $password; } } return null; } /** * Returns whether the user exists in the database or not. * * @param string $username the username to check * @return bool true if the user exists; false otherwise */ function authme_has_user($username) { $mysqli = authme_get_mysqli(); if ($mysqli !== null) { $stmt = $mysqli->prepare('SELECT 1 FROM ' . AUTHME_TABLE . ' WHERE username = ?'); $stmt->bind_param('s', $username); $stmt->execute(); return $stmt->fetch(); } // Defensive default to true; we actually don't know return true; } /** * Registers a player with the given username. * * @param string $username the username to register * @param string $password the password to associate to the user * @return bool whether or not the registration was successful */ function authme_register($username, $password) { $mysqli = authme_get_mysqli(); if ($mysqli !== null) { $hash = password_hash($password, PASSWORD_BCRYPT); $stmt = $mysqli->prepare('INSERT INTO ' . AUTHME_TABLE . ' (username, realname, password, ip) ' . 'VALUES (?, ?, ?, ?)'); $username_low = strtolower($username); $stmt->bind_param('ssss', $username, $username_low, $hash, $_SERVER['REMOTE_ADDR']); return $stmt->execute(); } return false; }