DEV Community

Morcos Gad
Morcos Gad

Posted on

Password Generator - PHP

Let's start. We want to create a strong password and control its size. Let's see the next code. I hope it helps you and use it in your projects

$lowercase = range('a','z');
$uppercase = range('A','Z');
$digits = range(0,9);
$special = ['!','@','#','$','%','^','&','*'];
$ch = array_merge($lowercase, $uppercase, $digits, $special);
$length = 8;

$password = array();
for($i = 0; $i <= $length; $i++){
  $int = rand(0, count($ch) - 1);
  array_push($password, $ch[$int]);
}
echo implode("",$password); 
Enter fullscreen mode Exit fullscreen mode

I hope you enjoyed the code
Source :- https://www.youtube.com/watch?v=Cv3MmZpxQvM

Top comments (0)