register.php
Código
<script type="text/javascript" src="sha1.js"></script> <script type="text/javascript"> //Función para validar el formulario function verificar_correo(texto) { var status = false; var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i; if (texto.search(emailRegEx) != -1) { status = true; } return status; } function validar() { var noerrors=1; var charset="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; var usu1=document.registro.usuario.value; var pas1=document.registro.pass.value; var pas2=document.registro.pass2.value; var email=document.registro.correo.value; if (usu1.length>3) { for (i=0;i<usu1.length;i++) { if (charset.indexOf(usu1.charAt(i),0)==-1) { alert("The username only can contain alphanumeric characters [a-z,A-Z,0-9], dashes [-] and underscores [_]."); noerrors=0; break; } } } else { alert("The username must be equal or longer than 4 characters."); } if (pas1!=pas2) { alert("The passwords doesn't match. Please, rewrite them."); noerrors=0; } else if (pas1.length<4 || pas2.length<4) { alert("Password must be equal or longer than 4 characters."); noerrors=0; } if (!(verificar_correo(email))) { alert("The email that you wrote is invalid."); noerrors=0; } var thecaptcha=<?php echo '"'.$_SESSION['captcha'].'"'; ?>; //aqui hay code php if (thecaptcha!=document.registro.captchacode.value) { alert(thecaptcha); alert("Please, write again the captcha, you don't writted it properly."); } document.registro.js.value=1; document.registro.pass=sha1(sha1(document.registro.pass.value)); document.registro.pass2=sha1(sha1(document.registro.pass2.value)); if (noerrors==1) { document.registro.submit(); } } </script> <img src="captcha.php">
captcha.php
Código
<?php $numcaracteres=8; $caracteres = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $codigo = ''; $i = 0; while ($i < $numcaracteres) { $i++; } $ancho = 300; $alto = 60; $_SESSION["captcha"] = $codigo; ?>