-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Integrate Login System with Database #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,50 +1,50 @@ | ||
| <?php | ||
| /********************************************************************** | ||
| * Author : Sergio Ceron Figueroa (sxceron@laciudadx.com) | ||
| * Alias : sxceron | ||
| * Web : http://www.dotrow.info | ||
| * Name : jShop v1.0 | ||
| * Desc : Valida un usuario para iniciar sesion | ||
| * userName : obligatorio (nombre de usuario) | ||
| * userPassword: obligatorio (password del usuario) | ||
| * | ||
| * | ||
| **********************************************************************/ | ||
| // Include file headers | ||
| include_once "./includes/validator.php"; | ||
| include_once "./includes/settings.php"; | ||
| include_once "./includes/db.php"; | ||
| include_once "./includes/security.php"; | ||
| $_validator = new Validator(); | ||
| $_validator->setMethod( "POST" ); | ||
| $_validator->setVars( array("userName:required", "userPassword:required") ); | ||
| if( $_validator->validate() ){ | ||
| $values = $_validator->getValues(); | ||
| $user = $db->get_row( "select * from usuarios where usuario_alias='".$values["userName"]."'" ); | ||
| if( $user->usuario_password == md5($values["userPassword"]) ){ | ||
| $_SESSION[ 'user_id' ] = $user->usuario_id; | ||
| $_SESSION[ 'user_alias' ] = $user->usuario_alias; | ||
| $_SESSION[ 'user_role' ] = $user->usuario_tipo; | ||
| $db->query( "update usuarios set usuario_ultimoacceso='".date("y/m/d")."' where usuario_id=".$user->usuario_id ); | ||
| if( $user->usuario_tipo == 2 ){ | ||
| header( 'Location: ./admin_ponencias.php'); | ||
| }else if( $user->usuario_tipo == 3 ){ | ||
| header( 'Location: ./evaluate_ponencias.php'); | ||
| }else{ | ||
| header( 'Location: ./adminpanel.php'); | ||
| } | ||
| }else{ | ||
| header( 'Location: ./login.php?id='.base64_encode( "2" ) ); | ||
| } | ||
| }else{ | ||
| for( $err="", $i = 0; $i < count($e = $_validator->getErrors()); $i++ ){ | ||
| $err = $err.";".$e[$i]["field"]; | ||
| } | ||
| header( 'Location: ./login.php?id='.base64_encode( "0" ).'&tk='.base64_encode($err) ); | ||
| } | ||
| <?php | ||
| /********************************************************************** | ||
| * Author : Sergio Ceron Figueroa (sxceron@laciudadx.com) | ||
| * Alias : sxceron | ||
| * Web : http://www.dotrow.info | ||
| * Name : jShop v1.0 | ||
| * Desc : Valida un usuario para iniciar sesion | ||
| * userName : obligatorio (nombre de usuario) | ||
| * userPassword: obligatorio (password del usuario) | ||
| * | ||
| * | ||
| **********************************************************************/ | ||
| // Include file headers | ||
| include_once "./includes/validator.php"; | ||
| include_once "./includes/settings.php"; | ||
| include_once "./includes/db.php"; | ||
| include_once "./includes/security.php"; | ||
|
|
||
| $_validator = new Validator(); | ||
| $_validator->setMethod( "POST" ); | ||
| $_validator->setVars( array("userName:required", "userPassword:required") ); | ||
|
|
||
| if( $_validator->validate() ){ | ||
| $values = $_validator->getValues(); | ||
|
|
||
| $user = $db->get_row( "SELECT * FROM usuarios WHERE usuario_alias='".$db->escape($values["userName"])."'" ); | ||
| if( $user && $user->usuario_password === md5($values["userPassword"]) ){ | ||
| $_SESSION[ 'user_id' ] = $user->usuario_id; | ||
| $_SESSION[ 'user_alias' ] = $user->usuario_alias; | ||
| $_SESSION[ 'user_role' ] = $user->usuario_tipo; | ||
| $db->query( "update usuarios set usuario_ultimoacceso='".date("y/m/d")."' where usuario_id=".$user->usuario_id ); | ||
| if( $user->usuario_tipo == 2 ){ | ||
| header( 'Location: ./admin_ponencias.php'); | ||
| }else if( $user->usuario_tipo == 3 ){ | ||
| header( 'Location: ./evaluate_ponencias.php'); | ||
| }else{ | ||
| header( 'Location: ./adminpanel.php'); | ||
| } | ||
| }else{ | ||
| header( 'Location: ./login.php?id='.base64_encode( "2" ) ); | ||
| } | ||
|
Comment on lines
+32
to
+41
|
||
|
|
||
| }else{ | ||
| for( $err="", $i = 0; $i < count($e = $_validator->getErrors()); $i++ ){ | ||
| $err = $err.";".$e[$i]["field"]; | ||
| } | ||
| header( 'Location: ./login.php?id='.base64_encode( "0" ).'&tk='.base64_encode($err) ); | ||
| } | ||
|
|
||
| ?> | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,7 +12,7 @@ public static function deleteAll($usuarios){ | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| public static function save($usuario){ | ||||||||
| public static function save($usuario, $db){ | ||||||||
| try{ | ||||||||
|
Comment on lines
+15
to
16
|
||||||||
| $sql = "insert into usuarios(usuario_nombre, usuario_apellidos, usuario_correo, usuario_telefono, usuario_direccion, usuario_nacimiento, usuario_alias, usuario_password, usuario_tipo) "; | ||||||||
| $sql .= "values('$usuario->getNombre()','$usuario->getApellidos()' "; | ||||||||
|
|
@@ -27,7 +27,7 @@ public static function save($usuario){ | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| public static function update($usuario){ | ||||||||
| public static function update($usuario, $db){ | ||||||||
| try{ | ||||||||
| $sql = "update usuarios set"; | ||||||||
| $sql .= " usuario_nombre = '$usuario->getNombre()',"; | ||||||||
|
|
@@ -59,19 +59,19 @@ public static function persist($usuario){ | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| public static function delete($usuario){ | ||||||||
| public static function delete($usuario, $db){ | ||||||||
| try { | ||||||||
| $db->query("delete from usuarios where usuario_id=$usuario->getId()"); | ||||||||
| $db->query("DELETE FROM usuarios WHERE usuario_id=".$db->escape($usuario->getId())); | ||||||||
|
||||||||
| $db->query("DELETE FROM usuarios WHERE usuario_id=".$db->escape($usuario->getId())); | |
| $usuarioId = (int) $usuario->getId(); | |
| $db->query("DELETE FROM usuarios WHERE usuario_id=".$usuarioId); |
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$db->get_results() returns rows as objects by default (ezSQL), but new Usuario($row) expects an associative array (it uses $row["usuario_id"], etc.). This will cause errors when hydrating users from queries. Either request ARRAY_A output from ezSQL (and pass an array into Usuario), or update Usuario’s constructor to handle ezSQL row objects.
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findById() builds ... where usuario_id=$id without escaping/validation. If $id can come from request parameters, this is SQL-injection prone. Cast $id to int or escape/quote appropriately before building the query.
| public static function findById($id, $db){ | |
| public static function findById($id, $db){ | |
| $id = (int)$id; |
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$db->get_row($sql) returns an object by default, but Usuario’s constructor expects an associative array. As written, new Usuario($row) will fail when $row is an object. Pass ARRAY_A as the second parameter to get_row() (or adjust Usuario to accept objects) to keep DAO hydration consistent.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ class UsuarioManager{ | |||||||||||||
| public static function registrarAdministrador($usuario){ | ||||||||||||||
| try{ | ||||||||||||||
| $usuario->setTipo(UsuarioType::ADMINISTRADOR); | ||||||||||||||
| UsuarioDao::persist($usuario); | ||||||||||||||
| UsuarioDao::persist($usuario, $GLOBALS['db']); | ||||||||||||||
| }catch(TransactionException $te){ | ||||||||||||||
|
Comment on lines
3
to
7
|
||||||||||||||
| throw $te; | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -47,39 +47,39 @@ public static function registrarAsistente($usuario){ | |||||||||||||
|
|
||||||||||||||
| public static function obtener($id){ | ||||||||||||||
| try{ | ||||||||||||||
| return UsuarioDao::findById($id); | ||||||||||||||
| return UsuarioDao::findById($id, $GLOBALS['db']); | ||||||||||||||
| }catch(QueryException $qe){ | ||||||||||||||
| throw $qe; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public static function eliminar($usuario){ | ||||||||||||||
| try{ | ||||||||||||||
| UsuarioDao::delete($usuario); | ||||||||||||||
| UsuarioDao::delete($usuario, $GLOBALS['db']); | ||||||||||||||
| }catch(TransactionException $te){ | ||||||||||||||
| throw $te; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public static function listar(){ | ||||||||||||||
| try{ | ||||||||||||||
| return UsuarioDao::findAll(); | ||||||||||||||
| return UsuarioDao::findAll($GLOBALS['db']); | ||||||||||||||
|
||||||||||||||
| return UsuarioDao::findAll($GLOBALS['db']); | |
| return UsuarioDao::findAll(); |
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UsuarioDao::findByQuery() returns an array of Usuario objects, but checkPassword() treats the result as a single Usuario ($usuario->getPassword()). This will fail (array has no getPassword). Either fetch the first element from the result array (and handle the empty case), or add a DAO method that returns a single user by alias.
| $usuario = UsuarioDao::findByQuery("usuario_alias='".$GLOBALS['db']->escape($_usuario->getAlias())."'", $GLOBALS['db']); | |
| $usuarios = UsuarioDao::findByQuery("usuario_alias='".$GLOBALS['db']->escape($_usuario->getAlias())."'", $GLOBALS['db']); | |
| if( count($usuarios) === 0 ){ | |
| return false; | |
| } | |
| $usuario = $usuarios[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Password verification is still using
md5(...). MD5 is not suitable for password hashing (fast and vulnerable to brute force). Migrate topassword_hash()on registration/update andpassword_verify()on login; if you must keep legacy hashes, consider a staged migration that re-hashes on successful login.