• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[ZNOTE ACC] Change login method from Username to Email address

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,074
Solutions
15
Reaction score
369
Location
Sweden
YouTube
Joriku
This took me a headache and a rage ctrl + a - replace all name with email to figure out on a late night with no sleep. So if you're in the same boat, listen up.

For later canary projects or TFS projects that wants to use Email and Password instead of Username.
1695570341674.png

Let's start by changing your login.php, usually located in layout/sub

This is not really needed, however. This makes sure that an email starting with something @ ends with something . something has to be written. "Type=Email" that is.
Change:
Lua:
<div class="username-box">
        username: <br>
        <input type="text" name="username">
</div>

To:
Lua:
<div class="username-box">
        Email: <br>
        <input type="email" name="username">
</div>

Now we enter engine/function/users.php

Find this:
Lua:
// Checks that username exist in database
function user_exist($username) {
    $username = sanitize($username);
    if (config('ServerEngine') !== 'OTHIRE')
        $data = mysql_select_single("SELECT `id` FROM `accounts` WHERE `name`='$username';");
    else
        $data = mysql_select_single("SELECT `id` FROM `accounts` WHERE `id`='$username';");
    return ($data !== false) ? true : false;
}

Replace with:
Lua:
// Checks that useremail exist in database
// Updated from name -> email
function user_exist($useremail) {
    $useremail = sanitize($useremail);
    if (config('ServerEngine') !== 'OTHIRE')
        $data = mysql_select_single("SELECT `id` FROM `accounts` WHERE `email`='$useremail';");
    else
        $data = mysql_select_single("SELECT `id` FROM `accounts` WHERE `id`='$useremail';");
    return ($data !== false) ? true : false;
}

Find:
Lua:
// Login with a user. (TFS 0.2)
function user_login($username, $password) {
    $username = sanitize($username);
    $password = sha1($password);
    if (config('ServerEngine') !== 'OTHIRE')
        $data = mysql_select_single("SELECT `id` FROM accounts WHERE name='$username' AND password='$password';");
    else
        $data = mysql_select_single("SELECT `id` FROM accounts WHERE id='$username' AND password='$password';");
    return ($data !== false) ? $data['id'] : false;
}

Replace with:
Lua:
// Login with a user. (TFS 0.2)
// Updated from name -> email
function user_login($useremail, $password) {
    $useremail = sanitize($useremail);
    $password = sha1($password);
    if (config('ServerEngine') !== 'OTHIRE')
        $data = mysql_select_single("SELECT `id` FROM accounts WHERE email='$useremail' AND password='$password';");
    else
        $data = mysql_select_single("SELECT `id` FROM accounts WHERE id='$useremail' AND password='$password';");
    return ($data !== false) ? $data['id'] : false;
}

Find:
Lua:
// Login a user with TFS 0.3 compatibility
function user_login_03($username, $password) {
    if (config('salt') === true) {
        $username = sanitize($username);
        $data = mysql_select_single("SELECT `salt`, `id`, `password`, `name` FROM `accounts` WHERE `name`='$username';");
        $salt = $data['salt'];
        if (!empty($salt)) $password = sha1($salt.$password);
        else $password = sha1($password);
        return ($data !== false && $data['name'] == $username && $data['password'] == $password) ? $data['id'] : false;
    } else return user_login($username, $password);
}

Replace with:
Lua:
// Login a user with TFS 0.3 compatibility
// Updated from name -> email
function user_login_03($useremail, $password) {
    if (config('salt') === true) {
        $useremail = sanitize($useremail);
        $data = mysql_select_single("SELECT `salt`, `id`, `password`, `email` FROM `accounts` WHERE `email`='$useremail';");
        $salt = $data['salt'];
        if (!empty($salt)) $password = sha1($salt.$password);
        else $password = sha1($password);
        return ($data !== false && $data['email'] == $useremail && $data['password'] == $password) ? $data['id'] : false;
    } else return user_login($useremail, $password);
}

This should be all you need to do in-order to change the method from using a username to logging in with an email address, I tried using an alternative login method. But it kept denying my request due to a token generated by default of Znote acc so this was a quick solution of my issue I came across.

Hope it helps.
 
Back
Top