Php generar password


/ Published in: PHP
Save to your folder(s)

Genera un string random del tipo especificado en $tipo y del tamaño pasado en $longitud.


Copy this code and paste it in your HTML
  1. function generarPassword( $longitud, $tipo = "alfanumerico" ){
  2. if ( $tipo=="alfanumerico" ){
  3. $exp_reg="[^A-Z0-9]";
  4. }elseif( $tipo=="alfa" ){
  5. $exp_reg="[^A-Z]";
  6. }elseif( $tipo=="numerico" ){
  7. $exp_reg="[^0-9]";
  8. }
  9. return substr( eregi_replace( $exp_reg, "", md5( time() ) ) .
  10. eregi_replace( $exp_reg, "", md5(time() ) ) .
  11. eregi_replace( $exp_reg, "", md5( time() ) ), 0, $longitud );
  12. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.