mercredi 26 octobre 2016

How can i set a string to zero after an expired time?

I am creating a login/registration-script where a user hast to activate his account with a token. Now i have a function that calls a random string.

class.functions.php

public static function generateRandomString($length = 200) {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $charactersLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
    }

this will output something like this: jTq7tH4dKy66dmnhRev5EjbZDZygN1...

now my question is, how can i set this string empty after 24h, so that the user has to activate his account again.

my thought was about an update query in my database like this:

$statusN = "N" and $statusY = "Y"

the table field from the database:

`user_status` ENUM('Y','N') NOT NULL DEFAULT 'N',

the sql statment:

$sql = "UPDATE formular SET user_status='" . $statusY . "' WHERE user_status='" . $statusN . "'";

but i dont know how to handel it with the time

Here is the inserting of the userdata and the activation_token

register.php

$activationToken = functions::generateRandomString();
    $stmt = $conn->prepare("INSERT INTO formular (firstname, second_firstname, lastname, zipcode, city, street, additionaladdress, country_id_from_apps_countries, username, email, hash, dday, dmonth, dyear, religion, housenumber, activation_token) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    $stmt->bind_param("sssisssssssssssss", $firstname, $secondFirstname, $lastname, $zipcode, $city, $street, $additionaladdress, $country, $username, $email, $hash, $DOB, $MOB, $YOB, $religion, $houseNumber, $activationToken);
    $stmt->execute();
    if ($stmt->affected_rows) {

    }




Aucun commentaire:

Enregistrer un commentaire