31 lines
1.3 KiB
Java
31 lines
1.3 KiB
Java
import java.sql.*;
|
|
|
|
public class DatabaseManager {
|
|
private static final String URL = "jdbc:mysql://db4free.net:3306/basecursos";
|
|
private static final String USERNAME = "edgarivanjc";
|
|
private static final String PASSWORD = "edgarivanJC12";
|
|
|
|
public static User getAuthenticatedUser(String nombre, String contrasena) {
|
|
User user = null;
|
|
try (Connection conexion = DriverManager.getConnection(URL, USERNAME, PASSWORD)) {
|
|
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;
|
|
}
|
|
}
|