Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. private static void addOrUpdateAccount(String account, String password, String level)
  2.     {
  3.         try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  4.             PreparedStatement ps = con.prepareStatement("REPLACE accounts(login, password, accessLevel) VALUES (?, ?, ?)"))
  5.         {
  6.             MessageDigest md = MessageDigest.getInstance("SHA");
  7.             byte[] newPassword;
  8.             newPassword = password.getBytes("UTF-8");
  9.             newPassword = md.digest(newPassword);
  10.            
  11.             ps.setString(1, account);
  12.             ps.setString(2, Base64.getEncoder().encodeToString(newPassword));
  13.             ps.setString(3, level);
  14.             if (ps.executeUpdate() > 0)
  15.             {
  16.                
  17.                 System.out.println("Account " + account + " has been created or updated");
  18.             }
  19.             else
  20.             {
  21.                 System.out.println("Account " + account + " does not exist");
  22.             }
  23.         }
  24.         catch (Exception e)
  25.         {
  26.             System.out.println("There was error while adding/updating account:");
  27.             System.out.println(e.getMessage());
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement