You are here

function aes_make_key in AES encryption 6

Same name and namespace in other branches
  1. 5 aes.module \aes_make_key()
  2. 7 aes.module \aes_make_key()
1 call to aes_make_key()
aes_get_key in ./aes.module

File

./aes.module, line 504

Code

function aes_make_key() {
  $acceptable = false;
  $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  while ($acceptable === false) {
    $key = "";
    while (strlen($key) < 32) {
      $key .= substr($chars, rand(0, strlen($chars)), 1);
    }
    $acceptable = true;

    //is there at least one lowercase letter?
    $result = preg_match("/.*[a-z].*/", $key);
    if ($result == 0) {
      $acceptable = false;
    }

    //is there at least one uppercase letter?
    $result = preg_match("/.*[A-Z].*/", $key);
    if ($result == 0) {
      $acceptable = false;
    }

    //is there at least one numeric?
    $result = preg_match("/.*[0-9].*/", $key);
    if ($result == 0) {
      $acceptable = false;
    }
  }
  return $key;
}