mercredi 10 juin 2020

How to create Random Password Generator using PHP?

This can generate random password.

<?php
function randomPassword() {
    $alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $pass = array();
    $alphaLength = strlen($alphabet) - 1;
    for ($i = 0; $i < 26; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass);
}

echo randomPassword();
?>

But I want to save this password in passwords.txt file. And next time when create a new password, it will check this password is in that passwords.txt or not. And than echo. If the password is already have, then go to the else condition and do it again. How can I write this code?




Aucun commentaire:

Enregistrer un commentaire