The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
strong passwords - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28)
+--- Forum: Modifications and Hackery (https://userspice.com/forums/forumdisplay.php?fid=29)
+--- Thread: strong passwords (/showthread.php?tid=147)



strong passwords - Ponchale - 05-28-2016

public algorithm to avoid registration of passwords weak informing the user.

<pre>
Code:
<?php

function checkPass($pass) {

     $count=strlen($pass);
    
    // Si el password tiene menos de 6 caracteres
    if ($count < 6) {
         return 'El password es muy corto.';
    }
  
    // Contamos cuantas mayusculas, minusculas, numeros y simbolos existen
    $upper = 0; $lower = 0; $numeros = 0; $otros = 0;
  
    for ($i = 0, $j = strlen($pass); $i < $j; $i++) {
        $c = substr($pass,$i,1);
        if (preg_match('/^[[:upper:]]$/',$c)) {
            $upper++;
        } elseif (preg_match('/^[[:lower:]]$/',$c)) {
            $lower++;
        } elseif (preg_match('/^[[:digit:]]$/',$c)) {
            $numeros++;
        } else {
            $otros++;
        }
    }

   // La constraseña debe tener 2 caracteres de al menos 2 diferentes
   // tipos  
    $max = $j - 2;
    if ($upper > $max) {
        return "El password tiene muchos caracteres en mayusucula.";
    }
    if ($lower > $max) {
        return "El password tiene muchos caracteres en minuscula.";
    }
    if ($numeros > $max) {
        return "El password tiene muchos caracteres numericos.";
    }
    if ($otros > $max) {
        return "El password tiene muchos caracteres especiales.";
    }      

    return false;
}

echo checkPass("password");
?>
</pre>