Overview
The Authentication component (Login.java) provides secure access control to the MatriculaUniPoo system. It validates user credentials against registration data and manages navigation between screens.
Component Architecture
Core Structure
The Login class maintains credential state and manages authentication flow:
public class Login extends javax.swing. JFrame {
private Registrar regis ;
private Matricula matri ;
private String regisDni ;
private String regisContra ;
public Login () {
this ( "" , "" );
initComponents ();
}
public Login ( String regisDni , String regisContra ) {
this . regisDni = regisDni;
this . regisContra = regisContra;
this . matri = new Matricula ();
matri . setLog ( this );
initComponents ();
}
}
The component supports two constructors: a default empty constructor and one that receives credentials from the registration process.
User Interface Design
Dual Panel Layout
The login screen features a modern two-panel design:
Left Panel (White)
Right Panel (Teal)
jPanel2 . setBackground ( new java. awt . Color ( 255 , 255 , 255 ));
jPanel2 . setForeground ( new java. awt . Color ( 0 , 153 , 255 ));
jLabel5 . setIcon ( new javax. swing . ImageIcon (
"C: \\ Users \\ Anghelo \\ Desktop \\ CerebroLogin.png"
));
The left panel displays branding imagery while the right panel contains the login form.
Username Field
DNI (National ID) serves as the unique username txtUsuario . setBackground ( new java. awt . Color ( 0 , 68 , 68 ));
txtUsuario . setForeground ( new java. awt . Color ( 255 , 255 , 255 ));
txtUsuario . setCaretColor ( new java. awt . Color ( 255 , 255 , 255 ));
Password Field
Secure password field with masked input pswContra . setBackground ( new java. awt . Color ( 0 , 68 , 68 ));
pswContra . setForeground ( new java. awt . Color ( 255 , 255 , 255 ));
pswContra . setCaretColor ( new java. awt . Color ( 255 , 255 , 255 ));
Authentication Logic
Credential Validation
The login system performs exact matching of credentials:
private void btnIniciarSesionActionPerformed ( java . awt . event . ActionEvent evt) {
String usuario = txtUsuario . getText ();
String contra = new String ( pswContra . getPassword ());
if ( usuario . equals (regisDni) && contra . equals (regisContra)) {
JOptionPane . showMessageDialog ( null , "INICIO EXITOSO" );
matri . setLog ( this );
matri . setVisible ( true );
matri . setLocationRelativeTo ( null );
this . setVisible ( false );
} else {
JOptionPane . showMessageDialog ( this ,
"USUARIO O CONTRASEÑA INCORRECTA" ,
"Error" ,
JOptionPane . ERROR_MESSAGE );
}
}
Both username (DNI) and password must match exactly for successful authentication. Partial matches are rejected.
Validation Flow
Authentication Process Breakdown
Extract Credentials
Retrieve username from text field
Extract password from password field using getPassword()
Compare Against Stored Values
Check if entered DNI matches regisDni
Verify password matches regisContra
Success Path
Display success message dialog
Initialize Matricula (enrollment) component
Navigate to enrollment screen
Hide login window
Failure Path
Show error dialog with descriptive message
Keep user on login screen
Allow retry without clearing fields
Security Considerations
Password Handling
The component uses JPasswordField for secure password entry:
pswContra = new javax. swing . JPasswordField ();
pswContra . setDisabledTextColor ( new java. awt . Color ( 255 , 255 , 255 ));
pswContra . setSelectedTextColor ( new java. awt . Color ( 255 , 255 , 255 ));
pswContra . setSelectionColor ( new java. awt . Color ( 255 , 255 , 255 ));
JPasswordField automatically masks password characters as bullets (•) to prevent shoulder surfing.
Passwords are extracted using the recommended getPassword() method:
String contra = new String ( pswContra . getPassword ());
This returns a char array instead of a String, allowing secure memory cleanup. The conversion to String happens only for comparison.
Navigation Management
Return to Registration
Users can navigate back to registration if they don’t have an account:
private void btnVolverActionPerformed ( java . awt . event . ActionEvent evt) {
regis . setLog ( this );
regis . setVisible ( true );
regis . setLocationRelativeTo ( null );
this . setVisible ( false );
}
Session Flow
From Registration
After successful registration, credentials are passed to Login constructor log = new Login (dni, contra);
log . setRegis ( this );
log . setVisible ( true );
Authentication
User enters credentials and attempts login
To Enrollment
Successful login navigates to Matricula (enrollment) screen matri . setLog ( this );
matri . setVisible ( true );
matri . setLocationRelativeTo ( null );
Component Interaction
Setter Methods for Navigation
The component provides setters to maintain references to other screens:
public void setRegis ( Registrar regis) {
this . regis = regis;
}
public void setMatri ( Matricula matri) {
this . matri = matri;
}
These bidirectional references enable seamless navigation between components while preserving state.
User Feedback
Success Dialog
Successful authentication displays a confirmation message:
JOptionPane . showMessageDialog ( null , "INICIO EXITOSO" );
Error Dialog
Failed authentication shows a descriptive error:
JOptionPane . showMessageDialog ( this ,
"USUARIO O CONTRASEÑA INCORRECTA" ,
"Error" ,
JOptionPane . ERROR_MESSAGE );
Success Message Generic success message without revealing which credential is correct
Error Message Generic error that doesn’t specify which field is incorrect (security best practice)
Visual Styling
Clear, instructive labels guide users:
jLabel1 . setFont ( new java. awt . Font ( "Segoe UI" , 1 , 14 ));
jLabel1 . setForeground ( new java. awt . Color ( 255 , 255 , 255 ));
jLabel1 . setText ( "Ingresa tus datos para INICIAR SESION:" );
jLabel3 . setText ( "USUARIO: DNI DEL ESTUDIANTE" );
jLabel4 . setText ( "CONTRASEÑA" );
Buttons follow the application’s color scheme:
btnIniciarSesion . setBackground ( new java. awt . Color ( 0 , 153 , 153 ));
btnIniciarSesion . setFont ( new java. awt . Font ( "Segoe UI" , 1 , 14 ));
btnIniciarSesion . setForeground ( new java. awt . Color ( 255 , 255 , 255 ));
btnIniciarSesion . setText ( "INICIAR SESION" );
Layout Structure
Absolute Layout Configuration
The form uses absolute positioning for precise control:
jPanel1 . setLayout ( new org. netbeans . lib . awtextra . AbsoluteLayout ());
jPanel1 . add (txtUsuario,
new org. netbeans . lib . awtextra . AbsoluteConstraints ( 50 , 130 , 286 , 30 ));
jPanel1 . add (pswContra,
new org. netbeans . lib . awtextra . AbsoluteConstraints ( 50 , 220 , 286 , 30 ));
Visual Separators
Separator lines organize the form visually:
jSeparator1 . setForeground ( new java. awt . Color ( 255 , 255 , 255 ));
jPanel1 . add (jSeparator1,
new org. netbeans . lib . awtextra . AbsoluteConstraints ( 6 , 37 , 330 , 10 ));
jSeparator2 . setForeground ( new java. awt . Color ( 255 , 255 , 255 ));
jPanel1 . add (jSeparator2,
new org. netbeans . lib . awtextra . AbsoluteConstraints ( 10 , 160 , 330 , 10 ));
Key Features
Credential Matching Exact string comparison for username and password validation
Secure Input Password field masks sensitive data during entry
Navigation Control Seamless transitions between registration, login, and enrollment
Error Handling Clear feedback for authentication failures