Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // M�todos do servidor RMI que o servidor TCP pode usar;
- // REGISTAR CONTA
- public String register(String username, String password) throws RemoteException {
- int check = 0;
- String resultado;
- // -------------------------------------
- // Verificar se o registo pode ser feito;
- // -------------------------------------
- Statement myStmt;
- try {
- myStmt = myConn.createStatement();
- ResultSet myRs = myStmt
- .executeQuery("SELECT USERNAME\n" + "FROM users\n" + "WHERE USERNAME ='" + username + "'");// results
- // set
- if (myRs.next()) {
- if (myRs.getString("USERNAME").equals(username)) {
- check = 1;
- }
- } else if (check == 0) {
- String sql = "INSERT INTO users (USERNAME, PASSWORD, ONLINE, USER_STATE)\n " + "VALUES ('" + username
- + "', '" + encryptPassword(password) + "', 0, 'active')";
- myStmt.executeUpdate(sql); // results set
- }
- // myRs.close();
- // myStmt.close();
- } catch (SQLException e) {// tratar exception de limite de carateres
- check = 1;
- e.printStackTrace();
- }
- if (check == 0) {
- resultado = "type: register, ok: true";
- } else {
- resultado = "type: register, ok: false";
- }
- return resultado;
- }
- // FAZER LOGIN
- public String login(String username, String password) throws RemoteException {
- int check = 0;
- String resultado;
- // -----------------------------------
- // Verificar se o login pode ser feito
- // -----------------------------------
- Statement myStmt;
- try {
- myStmt = myConn.createStatement();
- ResultSet myRs = myStmt.executeQuery("SELECT USERNAME, PASSWORD\n" + "FROM users\n" + "WHERE USERNAME ='"
- + username + "' AND PASSWORD = '" + encryptPassword(password) + "'");// results
- // set
- if (myRs.next()) {
- check = 0;
- String sql = "UPDATE users\n " + "SET ONLINE = 1\n" + "WHERE USERNAME ='" + username
- + "' AND PASSWORD = '" + encryptPassword(password) + "' ";
- myStmt.executeUpdate(sql); // results set
- } else {
- check = 1;
- }
- } catch (SQLException e) {
- check = 1;
- e.printStackTrace();
- }
- if (check == 0) {
- resultado = "type: login, ok: true";
- } else {
- resultado = "type: login, ok: false";
- }
- return resultado;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement