Files
jRDC-MultiDB-Hikari/ChangePassHandler.bas
jaguerrau 9c9e2975e9 - VERSION 5.10.27
- feat(arquitectura): Consolidación de estabilidad y diagnóstico.
- refactor: Arquitectura de base de datos local y políticas de logs.
- arch(sqlite): Aislamiento total de las conexiones SQLite en SQL_Auth y SQL_Logs. Esto protege las operaciones de autenticación críticas de la alta carga de I/O generada por el subsistema de logs.
- feat(logs): Implementación de modo de almacenamiento flexible para logs (disco o en memoria), mejorando la capacidad de testing.
- refactor(logs): Se estandariza el límite de retención de registros a 10,000 para todas las tablas de logs, y se renombra la subrutina de limpieza a borraArribaDe10000Logs.
2025-10-29 05:25:56 -06:00

51 lines
1.6 KiB
QBasic

B4J=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=10.3
@EndOfDesignText@
'Class module: ChangePassHandler
Sub Class_Globals
Private bc As BCrypt
End Sub
Public Sub Initialize
bc.Initialize("BC")
End Sub
Public Sub Handle(req As ServletRequest, resp As ServletResponse)
Log("--- CHANGEPASSHANDLER FUE LLAMADO ---")
If req.GetSession.GetAttribute2("user_is_authorized", False) = False Then
resp.SendRedirect("/login")
Return
End If
Dim currentUser As String = req.GetSession.GetAttribute("username")
Dim currentPass As String = req.GetParameter("current_password")
Dim newPass As String = req.GetParameter("new_password")
Dim confirmPass As String = req.GetParameter("confirm_password")
If newPass <> confirmPass Then
resp.Write("Las contraseñas no coinciden.")
Return
End If
Try
' 1. Verification of the current password hash using SQL_Auth.
Dim storedHash As String = Main.SQL_Auth.ExecQuerySingleResult2("SELECT password_hash FROM users WHERE username = ?", Array As String(currentUser))
Log("Valor de la BD (storedHash): " & storedHash)
If storedHash = Null Or bc.checkpw(currentPass, storedHash) = False Then
resp.Write("Contraseña actual incorrecta.")
Return
End If
' 2. Hashing and updating the new password using SQL_Auth.
Dim newHashedPass As String = bc.hashpw(newPass, bc.gensalt)
Main.SQL_Auth.ExecNonQuery2("UPDATE users SET password_hash = ? WHERE username = ?", Array As Object(newHashedPass, currentUser))
resp.Write("Contraseña cambiada exitosamente.")
Catch
Log(LastException)
resp.Write("Error interno al cambiar la contraseña.")
End Try
End Sub