top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to create random password in php?

–1 vote
312 views

I want to create a One Time Password(OTP) for my site. I need some random password for the user, can anyone tell me how it can be done.

posted Mar 25, 2016 by Pratiksha Shetty

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

See the following code from the QueryHome, what you need is random number generator for the given length -

function poweredby_alphanum($length)
{
  $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; //<You can set any string here>
  $charactersLength = strlen($characters);
  $randomString = '';
  for ($i = 0; $i < $length; $i++) {
    $randomString .= $characters[mt_rand(0, $charactersLength - 1)];
  }

  return $randomString;
}
answer Mar 25, 2016 by Salil Agrawal
Similar Questions
+10 votes

I want to save a password in encrypted form, so that it will not be understand by human. Is it possible ? If yes then please explain briefly.

+1 vote

I'm trying to pull the password policy response message from ldap_bind() method: password is expiring, password expired etc.

While checking the packet content from OpenLDAP after ldap_bind() request, with Wireshark, there is a control hooked to the ldap_bind() response, were the message code and message text about password expiration is, but I can't manage to parse that message from response.

I set the password policy request server control before the bind with ldap_set_option(). Any workaround or what am I doing wrong?

...