• 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!

AAC gesior - get Recovery Key

Fortera Global

Intermediate OT User
Joined
Nov 20, 2015
Messages
1,182
Solutions
2
Reaction score
117
I'm trying one code to: player will need write recovery key in some field for continue..
something like this:

Edited:

PHP:
$main_content .= '<TD WIDTH=10%><input required name="key" type=text min="2" max="10"></TD>';

$rec_key = trim($_REQUEST['key']);
    
        $temp_account = new Account();
        $account_key = $temp_account->getCustomField('key');
    
        if(empty($account_key))
                {
                    $main_content .= 'Administrator, recovery key is empty';
                }else
                {
                    if(!$account_key == $rec_key)
                        {
            $main_content .= 'Administrator, recovery key could not be found';
                }else
                {
        $temp_account->find($config['site']['charactertrade']['secret_account_name']);
        if (!$temp_account->isLoaded())
        {
            $main_content .= 'Administrator, secret account could not be found';
        }else
        {
            $main_content .= 'something here';
    }

  }
 
Last edited by a moderator:
Solution
Then you don't mean min and max, but minlength and maxlength in your input.

Like this:
Code:
<TD WIDTH=10%><input required name="key" type=text minlength="2" maxlength="10"></TD>

And to validate, you can do this, like this:
PHP:
if(!isset($_POST['key']) || empty($_POST['key'])) {
    // no recovery key sent or empty
}
else {
    $key = $_POST['key'];
    $len = strlen($key);
    if($len < 2 || $len > 10) {
        // recovery key too long, or too short
    }
    else {
        if($temp_account->getCustomField('key') != $key) {
            // key is not same on account
        }
        else {
            // all ok
        }
    }
}
Just showing you how to comment your code in php.
comments are defined in php as either 2 forward slashes known as an inline comment
PHP:
// everything til the end of the line is ignored by the server
or a block comment
PHP:
/*
   This is a block comment and will be ignored by the server
*/
 
assuming you have a `FIELD` called `rec_key`

HTML
Code:
<form id="" action="/?subtopic=somePage" method="post">
       <input type="text" name="rec_key" placeholder="Enter Recovery Key">
       <input type="subtmit" name="submit" value="Send">
</form>

PHP
now assuming that the PHP script is inside a file called "somePage.php"
PHP:
<?php

           // Checking if the field is empty or not
           if( isset($_POST['rec_key']) && !empty($_POST['rec_key']) ){
                  // True, the rec key was submitted
                  // do something with the rec key
           } else {
                  // False, rec key was not set
           }

?>
 
assuming you have a `FIELD` called `rec_key`

HTML
Code:
<form id="" action="/?subtopic=somePage" method="post">
       <input type="text" name="rec_key" placeholder="Enter Recovery Key">
       <input type="subtmit" name="submit" value="Send">
</form>

PHP
now assuming that the PHP script is inside a file called "somePage.php"
PHP:
<?php

           // Checking if the field is empty or not
           if( isset($_POST['rec_key']) && !empty($_POST['rec_key']) ){
                  // True, the rec key was submitted
                  // do something with the rec key
           } else {
                  // False, rec key was not set
           }

?>
worked, but is the same above, thanks man <3
 
PHP:
<TD WIDTH=10%><input required name="key" type=text min="2" max="10"></TD>

how to make the script read this field above? If RK is correctly continue, else error
 
PHP:
if(!isset($_POST['key']) || empty($_POST['key'])) {
    // no recovery key sent or empty
}
else {
    if(!is_numeric($_POST['key']) || (int)$_POST['key'] < 2 || (int)$_POST['key'] > 10) {
        // recovery key not number, too big or too small
    }
    else {
        // your action
    }
}
 
PHP:
if(!isset($_POST['key']) || empty($_POST['key'])) {
    // no recovery key sent or empty
}
else {
    if(!is_numeric($_POST['key']) || (int)$_POST['key'] < 2 || (int)$_POST['key'] > 10) {
        // recovery key not number, too big or too small
    }
    else {
        // your action
    }
}
thanks again.
The RK can be by letters or numbers. And how to check if the RK of the char is correct according to the account?

Actually:

PHP:
$temp_account = new Account();
        $temp_account->find($config['site']['charactertrade']['secret_account_name']);
        if (!$temp_account->isLoaded())
        {
            $main_content .= 'Administrator, account could not be found';
        } else if(!isset($_POST['key']) || empty($_POST['key'])) {
        // no recovery key sent or empty
        $main_content .= 'Empty key.';
        }
        else if (!is_numeric($_POST['key']) || (int)$_POST['key'] < 2 || (int)$_POST['key'] > 10) {
        // recovery key not number, too big or too small
        $main_content .= 'Wrong key.';
        }
        else
        { // continue...
 
Then you don't mean min and max, but minlength and maxlength in your input.

Like this:
Code:
<TD WIDTH=10%><input required name="key" type=text minlength="2" maxlength="10"></TD>

And to validate, you can do this, like this:
PHP:
if(!isset($_POST['key']) || empty($_POST['key'])) {
    // no recovery key sent or empty
}
else {
    $key = $_POST['key'];
    $len = strlen($key);
    if($len < 2 || $len > 10) {
        // recovery key too long, or too short
    }
    else {
        if($temp_account->getCustomField('key') != $key) {
            // key is not same on account
        }
        else {
            // all ok
        }
    }
}
 
Solution
Then you don't mean min and max, but minlength and maxlength in your input.

Like this:
Code:
<TD WIDTH=10%><input required name="key" type=text minlength="2" maxlength="10"></TD>

And to validate, you can do this, like this:
PHP:
if(!isset($_POST['key']) || empty($_POST['key'])) {
    // no recovery key sent or empty
}
else {
    $key = $_POST['key'];
    $len = strlen($key);
    if($len < 2 || $len > 10) {
        // recovery key too long, or too short
    }
    else {
        if($temp_account->getCustomField('key') != $key) {
            // key is not same on account
        }
        else {
            // all ok
        }
    }
}

Thanks, I changed a little cuz was not worked (the elses), and now is always giving it is not the correctly RK, but it is the correctlyo_O

PHP:
$temp_account = new Account();
        $temp_account->find($config['site']['charactertrade']['secret_account_name']);
        $key = $_POST['key'];
        $len = strlen($key);
     
        if (!$temp_account->isLoaded())
        {
            // secret account wrong
        } else if(!isset($_POST['key']) || empty($_POST['key'])) {
        // RK EMPTY
        }
        else if($len < 2 || $len > 10) {
        // too short or too long
    }
         else if($temp_account->getCustomField('key') != $key) {
            // key is not same on account

        }
        else
        { // continue script ~~. ..
 
Here is an example of the lost account page, but I do not know how to copy the code correctly to enter the other one:

PHP:
$rec_key = trim($_REQUEST['key']);
        $nick = $_REQUEST['nick'];
        if(check_name($nick))
        {
            $player = new Player();
            $account = new Account();
            $player->find($nick);
            if($player->isLoaded())
                $account = $player->getAccount();
            if($account->isLoaded())
            {
                $account_key = $account->getCustomField('key');
                if(!empty($account_key))
                {
                    if($account_key == $rec_key)
                    {/////
 
I quite not understand what doesn't work. Cause everything looks good. Can you post the full script? Also, are you sure your key in accounts table doesn't contain spaces? In this case, you will need to trim() it too.
 
I quite not understand what doesn't work. Cause everything looks good. Can you post the full script? Also, are you sure your key in accounts table doesn't contain spaces? In this case, you will need to trim() it too.

how to trim it?

PS. RK doesnt contain spaces
 
Back
Top