mezontleTeam/DatabaseManager.java

35 lines
1.3 KiB
Java
Raw Normal View History

2024-03-03 22:08:11 +00:00
import java.sql.*;
public class DatabaseManager {
2024-03-04 14:47:47 +00:00
// private static final String URL = "jdbc:mysql://db4free.net:3306/basecursos";
// private static final String USERNAME = "edgarivanjc";
// private static final String PASSWORD = "edgarivanJC12";
2024-03-03 22:08:11 +00:00
public static User getAuthenticatedUser(String nombre, String contrasena) {
User user = null;
2024-03-04 14:47:47 +00:00
try (Connection conexion = ConexionBD.getConnection()){
2024-03-03 22:08:11 +00:00
String consulta = "SELECT * FROM usuarios WHERE nombre = ? AND contrasena = ?";
try (PreparedStatement statement = conexion.prepareStatement(consulta)) {
statement.setString(1, nombre);
statement.setString(2, contrasena);
try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) {
int id = resultSet.getInt("id");
String nombreUsuario = resultSet.getString("nombre");
String email = resultSet.getString("email");
String contrasenaUsuario = resultSet.getString("contrasena");
user = new User(id, nombreUsuario, email, contrasenaUsuario);
}
}
}
} catch (SQLException ex) {
ex.printStackTrace();
}
return user;
}
2024-03-04 14:47:47 +00:00
2024-03-03 22:08:11 +00:00
}