Previous Article

PHP function to generate a random password

Next Article

This simple function generates a random password using all alphanumeric characters. While this won't be the most secure password, it is better than a dictionary word. The function accepts an integer to determine the password length, but if one isn't passed defaults to 16.

function password_generator($length = 16)
{
    $str = 'abcdefghijkmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    for ($i = 0, $password = ''; $i < $length; $i++) {
        $password .= substr($str, mt_rand(0, strlen($str) - 1), 1);
    }
    return $password;
}
Avatar of Clive Walkden

Clive Walkden

Posted:

Latest Articles

Linux command line tools, installations etc

Linux

How to Install NordLayer VPN Client on Ubuntu 20.04 and Connect to a Virtual Network

A simple to follow installation guide for NordLayer VPN

MySQL usage, tweaks and learnings

MySQL

Mastering MySQL Database Imports on Linux

Learn efficient ways to import MySQL databases on Linux using the mysql command-line client. Explore the --source option and < operator for seamless data migration. Master MySQL imports on Linux with our comprehensive guide.

DevOps principles and tool usage

DevOps

Mastering SSH Key Conversions for DevOps

A guide to convert SSH keys from one version to another using Linux CLI