Ver Mensaje Individual
  #6 (permalink)  
Antiguo 27/12/2006, 01:48
Gustavo_AR
 
Fecha de Ingreso: septiembre-2006
Ubicación: Argentina
Mensajes: 190
Antigüedad: 17 años, 8 meses
Puntos: 1
Re: Password aleatorio al haer click a un boton

//ACA EL LINK AL EJEMPLO. NOTA: LO HICE COPIANDO Y PEGANDO DIRECTAMENTE LO QUE POSTEE ABAJO, ASÍ QUE NO PUEDE FALLAR.

http://www.imagenshare.com.ar/prueba/password.html


Esto lo pones entre head y /head

Código PHP:
<script language="JavaScript" type="text/JavaScript">

function 
FX_passGenerator(form,element) {
  var 
thePass "";
  var 
randomchar "";
  var 
numberofdigits Math.floor((Math.random() * 7) + 6);
  for (var 
count=1count<=numberofdigitscount++) {
    var 
chargroup Math.floor((Math.random() * 3) + 1);
    if (
chargroup==1) {
      
randomchar Math.floor((Math.random() * 26) + 65);
    }
    if (
chargroup==2) {
      
randomchar Math.floor((Math.random() * 10) + 48);
    }
    if (
chargroup==3) {
      
randomchar Math.floor((Math.random() * 26) + 97);
    }
    
thePass+=String.fromCharCode(randomchar);
  }
  eval(
'document.'+form+'.'+element+'.value = thePass');
}

</script> 
Ahora, en donde queres poner el botón pones lo siguiente:

Código HTML:
<form  name="form1" method="post" action="">

<input name="password" type="text" value="" size="25" maxlength="25">
      
<input type="button" onClick="FX_passGenerator('form1','password')" value="Generar">

</form> 
fijate bien que FX_passGenerator('form1','password') se refiere al nombre del form y al campo en donde se va a insertar el pass aleatorio.

Saludos.