Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void registarUtilizador(String username, String password) throws SQLException {
- Connection conn = getConnection();
- Statement stat = conn.createStatement();
- int id_utilizador = randomGenerator.nextInt(1000);
- try {
- stat.execute("INSERT into Utilizadores (id_utilizador,username,password) VALUES ('"+id_utilizador+"','"+username+"','"+password+"')");
- System.out.println("Utilizador registado");
- conn.commit();
- } catch (SQLException e) {
- // log the warning...
- e.printStackTrace();
- }
- }
- public void login(String username, String password) throws SQLException {
- int flag=0;
- Connection conn = getConnection();
- String query = "SELECT Utilizadores.username, Utilizadores.password FROM Utilizadores WHERE Utilizadores.username = ('"+username+"') AND Utilizadores.password = ('"+password+"')";
- Statement stat = conn.createStatement();
- try {
- ResultSet rs = stat.executeQuery(query);
- while(rs.next()) {
- System.out.println("Utilizador autenticado");
- flag = 1;
- }
- if (flag==0)
- System.out.println("Utilizador não autenticado");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement