Created
September 20, 2012 08:43
-
-
Save abrahamjso/3754708 to your computer and use it in GitHub Desktop.
rsaAutentification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="home.php">Regresar</a><br/> | |
<?php | |
validar($_POST['user'], $_POST['respuesta'], $_POST['x']); | |
function validar($usuario, $r, $x) | |
{ | |
$lista = getUser($usuario); | |
if($lista) | |
{ | |
$e = $lista[0]; | |
$n = $lista[1]; | |
$y = f($x); | |
$num = fastmodexp($r, $e, $n); | |
if($y == $num) | |
{ | |
echo "<h3>Welcome $usuario</h3>"; | |
echo "You can see 9gag<br/><br/>"; | |
echo "<iframe src='http://www.9gag.com' width='900' height='900'></iframe>"; | |
} | |
else echo "Fail..!"; | |
echo "<br/><br/>"; | |
} | |
else | |
{ | |
echo "<h1>Usuario invalido<h1>"; | |
die(); | |
} | |
} | |
function getUser($usuario) | |
{ | |
include 'parametrosLogin/loginConnection.php'; | |
$link_C = "SELECT e, n FROM rsa_cripto where usuario = '".$usuario."'"; | |
$link_CR = mysql_query($link_C, $conexion) or die(mysql_error()); | |
$link_C_rows = mysql_num_rows($link_CR); | |
if ($link_C_rows> 0) { | |
while ($link_C_Rrows = mysql_fetch_assoc($link_CR)) { | |
$e = $link_C_Rrows['e']; | |
$n = $link_C_Rrows['n']; | |
} | |
$lista = array($e, $n); | |
return $lista; | |
} | |
else return False; | |
} | |
function f($x) | |
{ | |
return ($x*2)+5; | |
} | |
function fastmodexp($x, $y, $mod) | |
{ | |
$p = 1; | |
$aux = $x; | |
while($y > 0){ | |
if ($y % 2 == 1){ | |
$p = ($p * $aux) % $mod; | |
} | |
$aux = ($aux * $aux) % $mod; | |
$y = $y >> 1; | |
} | |
return ($p); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment