The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
strong passwords
#1
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>
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)