I am programming a simple forum script (yes, I know, there is a lot of open source scripts in the web) and I started with the users system (registry of users and login)
For security, I am using sha256 to encript the password, in two pass:
1) In one file I have the Salt text, encripted in md5... for example:
2) In the Users Registry script I encript the password:Code:$salt = hash(md5, 'starwars')
I think you saw that I "double encript" the Salt text (the variable $salt is saved in a configuration file, and I call the file using require() )Code:$password = hash(sha256, $salt . $HTTP_POST_VARS["password"]
3) All works well, the user's info is saved in the mysql, etc
4) Now I am going to try the login script...
5) The login script consist in a html file:
6) this file redirects me to a php script that create "cookies" with the required info:Code:<FORM ACTION="1.php" METHOD="post"> Nick : <INPUT TYPE="text" NAME="nick" SIZE="20" MAXLENGTH="20"> <BR> Password: <INPUT TYPE="password" NAME="password" SIZE="28" MAXLENGTH="20"> <BR> <INPUT TYPE="submit" CLASS="boton" VALUE="Ingresar"> </FORM>
this script encript the password :lockd:Code:<?php setcookie("nick",$HTTP_POST_VARS["nick"],time()+7776000); setcookie("pass",hash('sha256', '$salt . $HTTP_POST_VARS["password"]'),time()+7776000); ?> <SCRIPT LANGUAGE="javascript"> location.href = "2.php"; </SCRIPT>
7) the script redirects me to a second file with the function of validate the cookies info:
Code:<?php require(imaginary_config_file.php'); function quitar($mensaje) { $mensaje = str_replace("<","<",$mensaje); $mensaje = str_replace(">",">",$mensaje); $mensaje = str_replace("\'","'",$mensaje); $mensaje = str_replace('\"',""",$mensaje); $mensaje = str_replace("\\\\","\\",$mensaje); return $mensaje; } if(trim($HTTP_COOKIE_VARS["nick"]) != "" && trim($HTTP_COOKIE_VARS["pass"]) != "") { $passN = quitar($HTTP_COOKIE_VARS["pass"]); $nickN = quitar($HTTP_COOKIE_VARS["nick"]); $result = mysql_query("SELECT password FROM usuarios WHERE nick='$nickN'"); if($row = mysql_fetch_array($result)) { if($row["password"] == $passN) { //90 dias dura la cookie setcookie("usNick",$nickN,time()+7776000); setcookie("usPass",$passN,time()+7776000); ?> Ingreso exitoso, ahora sera dirigido a la pagina principal. <? } else { echo "Password incorrecto"; } } else { echo "Usuario no existente en la base de datos"; } mysql_free_result($result); } else { echo "Debe especificar un nick y password"; } mysql_close(); ?>I think is a really secure metod with offers security for me and the users... well, here is where I get the error:
9) Note that this is not my first attempt for made this script work, I tested three differents metods, with the same resultCode:Warning: Cannot modify header information - headers already sent by (output started at /home/samurais/public_html/pruebas/ingresar_user2.php:1) in ------------/2.php on line 25 Warning: Cannot modify header information - headers already sent by (output started at /home/samurais/public_html/pruebas/ingresar_user2.php:1) in -----------/2.php on line 26 Ingreso exitoso, ahora sera dirigido a la pagina principal.
Please help me!!!
p.d: All the file names and other things that represents a security issue for me and x10hosting were changed
p.d 2: sorry for my english, I only have 13 years xD
p.d 3: I tested only the script that creates the first cookies and I don't have any problem, I used the firefox extension Web Developer to saw the cookies and all is in his place


LinkBack URL
About LinkBacks
I think is a really secure metod with offers security for me and the users... well, here is where I get the error:

Reply With Quote


