php code to generate strong password

Solutions on MaxInterview for php code to generate strong password by the best coders in the world

showing results for - "php code to generate strong password"
Philipp
07 Mar 2019
1<?php  
2  function randomPassword() {
3    $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
4    $pass = array(); //remember to declare $pass as an array
5    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
6    for ($i = 0; $i < 8; $i++) {
7        $n = rand(0, $alphaLength);
8        $pass[] = $alphabet[$n];
9    }
10    return implode($pass); //turn the array into a string
11  }
12
13  echo randomPassword();
14