Skip to content

Instantly share code, notes, and snippets.

@younes-dro
Created January 9, 2020 05:37
Show Gist options
  • Select an option

  • Save younes-dro/91ce28d78baa116e9b261dc44a4254f3 to your computer and use it in GitHub Desktop.

Select an option

Save younes-dro/91ce28d78baa116e9b261dc44a4254f3 to your computer and use it in GitHub Desktop.
Verify a pattern : 6 char lenght ( 3 string and 3 number)
if(isset($_POST['log']) && !empty($_POST['log']) && $_POST['log']==1){
$login = trim($_POST['login']);
$pw = trim($_POST['pw']);
if(strlen($login) == 6 && strlen($pw) == 6){
$n_log=0;
$l_log=0;
$n_p=0;
$l_p=0;
for($i=0; $i<strlen($login); $i++){
$numeric = '/[0-9]/';
$lettre = '/[a-zA-Z]/';
$char = substr($login,$i,1);
//echo "$char <br>";
if(preg_match($numeric,$char)){
$n_log++;
}
if(preg_match($lettre,$char)){
$l_log++;
}
}
if($n_log !=3 || $l_log !=3){
echo '{"val1":"le login doit avoir excatment 3 lettres et 3 chiffre ","val2":"0"}';
exit();
}
for($i=0; $i<strlen($pw); $i++){
$numeric = '/[0-9]/';
$lettre = '/[a-zA-Z]/';
$char = substr($pw,$i,1);
//echo "$char <br>";
if(preg_match($numeric,$char)){
$n_p++;
}
if(preg_match($lettre,$char)){
$l_p++;
}
}
if($n_p !=3 || $l_p !=3){
echo '{"val1":"le mote de passe doit avoir excatment 3 lettres et 3 chiffre ","val2":"0"}';
exit();
}
echo '{"val1":"Bonjour Mr <b>'.$login.'</b>","val2":" veuillez <a href=\'galerie.php\'>confirmer</a> votre demande d’accès."}';
}else{
echo '{"val1":"le Login et le mot de passe font 6 caracteres (3 chiffres et 3 lettres )pour chacun","val2":"0" }';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment