Пример #1
0
function forgotCredentials($emailAddress)
{
    //Checks if email address exists
    if (!checkIfEmailExists($emailAddress)) {
        print 'enot';
    }
    //Create database query
    $databaseQuery = "SELECT * FROM login WHERE emailAddress='{$emailAddress}'";
    //Execute query
    $result = executeDatabase($databaseQuery);
    //While statement... Get data from database
    while ($row = mysqli_fetch_array($result)) {
        $obj = createInstance();
        //Strings
        $username = $row['username'];
        $password = $row['password'];
        $hash = $row['hash'];
        $confirmHash = $hash . $password;
        $reset_url = $obj->reset_url() . $confirmHash . "&email=" . $emailAddress;
        //Create Email
        $subject = 'Request Login Credentials';
        $message = "Username:{$username}\nPassword:{$reset_url}";
        //Send email
        sendEmail($message, $row['emailAddress'], $subject);
        print 'Correct';
    }
}
        sendEmailTo($email, $md5VersionOFEmail, $firstName, $lastName);
        echo "<script type='text/javascript'>\n            alert('Email sent to your following email account! Please check your email address for more information.');\n            history.go(-2);</script>";
    } else {
        echo "<script type='text/javascript'>\n            alert('Unable to send the email. Please try again.');\n            history.go(-1);\n        </script>";
    }
}
function checkIfEmailExists()
{
    $conn = connectToDatabase();
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    $email = $_POST['email'];
    $sql = "SELECT * FROM Players where Players.Email = '{$email}';";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {
            updateResetKeyOfPlayerWithEmail($email, $row['First_Name'], $row['Last_Name']);
            break;
        }
    } else {
        echo "<script type='text/javascript'>\n            alert('No email found on file. Please try again.');\n            history.go(-1);\n        </script>";
    }
    $conn->close();
}
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
    echo "<script type='text/javascript'>\n            alert('A valid email address is required. Please try again.');\n            history.go(-1);\n        </script>";
} else {
    checkIfEmailExists();
}