Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a complex login password for rackspace mail api
<?php
/*
Create a complex 8 character password which meets (exceeds actually) the rackspace mail requirements.
Author: craig@123marbella.com ON 27/9/2017
This function allows you to specify the length of the password and the specific characters to include in the password.
Compleletly random passwords look ugly, so this function will build the password into a random and complex, yet friendlier looking password.
EG: Man$6256 or Lin%9082
This is expecially useful if you need to give the password to a client over the phone or read the password out.
You can meet ALL the following requirements with this function:
At least 8 characters long
One lowercase character
One uppercase character
One number
One non-alphanumeric character (!, $, #, %, etc)
NO sequential numbers (EG: 123 or 456 or 789 etc)
NOTE: passwords should always be as long as possible, not just 8 chars! But this password is a starting pinit for clients.
*/
function create_rackspace_mail_email_password() {
//generate the first part of the password for the user
//to avoid readibility issues for end users, avoid using 0,i,l
$length = 4;
$chars = "abcdefghjkmnpqrstuvwxyz";
$first_part = substr(str_shuffle($chars),0,$length);
//generate the second part of the password for the user
//add more non-alphanumeric characters to $chars if you want
//I suggest only adding the more common ones as on mobile
//and foreign keyboards its sometimes hard to find the symbols.
$length = 1;
$chars = "$#%!";
$second_part = substr(str_shuffle($chars),0,$length);
//generate the third part of the password for the user
//to avoid sequential numbers, use: 02468 for $chars
$length = 3;
$chars = "02468";
$third_part = substr(str_shuffle($chars),0,$length);
//join all togther to form password and capitalise the first letter
return ucfirst($first_part . $second_part. $third_part);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.