Ver Mensaje Individual
  #8  
Antiguo 01-02-2008
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.107
Reputación: 34
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola,

Hombre, el algoritmo podrá mejorarse lo que se quiera (de hecho, reconozco que yo trabajé más en la "integración" con jQuery, en lo que es el plugin, en cómo puede usarse) pero, tengo que decir que no se basa sólo en la longitud. Aquí están los dos métodos principales del plugin, para que pueda verse. Ah, ¡y se admiten sugerencias!

Código PHP:
  function checkRepetition(pLenstr){
    var 
res '';
    for(
0str.lengthi++){
      var 
repeated true;
      for(
0pLen && (pLen) < str.lengthj++){
        
repeated repeated && (str.charAt(i) == str.charAt(pLen));
      }
      if(
pLen){
        
repeated false;
      }
      if(
repeated){
        
+= (pLen 1);
        
repeated false;
      }else{
        
res += str.charAt(i);
      }
    }
    return 
res;
  };       
  
  function 
passwordStrength(password){
    var 
score 0;
    if(
password.length == 0){
      return 
emptyPassResult;
    }else if(
password.length ){ 
      return 
shortPassResult;
    }
    
score += (password.length 4);
    
score += (checkRepetition(1password).length password.length);
    
score += (checkRepetition(2password).length password.length);
    
score += (checkRepetition(3password).length password.length);
    
score += (checkRepetition(4password).length password.length);
    
// password has 3 numbers
    
if(password.match('/(.*[0-9].*[0-9].*[0-9])/')){
      
score += 5;
    } 
    
// password has 2 sybols
    
if(password.match('/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/'))
    {
      
score += 5;
    }    
    
// password has Upper and Lower chars
    
if(password.match('/([a-z].*[A-Z])|([A-Z].*[a-z])/')){
      
score += 10;
    }    
    
// password has number and chars
    
if(password.match('/([a-zA-Z])/') && password.match('/([0-9])/')){
      
score += 15;
    }
    
// password has number and symbol
    
if(password.match('/([!,@,#,$,%,^,&,*,?,_,~])/'
     && 
password.match('/([0-9])/')){
       
score += 15;
    }
    
// password has char and symbol
    
if(password.match('/([!,@,#,$,%,^,&,*,?,_,~])/'
     && 
password.match('/([a-zA-Z])/')){
       
score += 15;
    }
    
// password is just a nubers or chars
    
if(password.match('/^\w+$/') || password.match('/^\d+$/')){
      
score -= 10;
    }
    if(
score 0){
      
score 0;
    }
    if(
score 100){
      
score 100;
    }
    if(
score 34){
      return 
badPassResult;
    }
    if(
score 68){
      return 
goodPassResult;
    }
    return 
strongPassResult;
  }; 
__________________
David Esperalta
www.decsoftutils.com
Responder Con Cita