Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void addOrUpdateAccount(String account, String password, String level)
- {
- try (Connection con = L2DatabaseFactory.getInstance().getConnection();
- PreparedStatement ps = con.prepareStatement("REPLACE accounts(login, password, accessLevel) VALUES (?, ?, ?)"))
- {
- MessageDigest md = MessageDigest.getInstance("SHA");
- byte[] newPassword;
- newPassword = password.getBytes("UTF-8");
- newPassword = md.digest(newPassword);
- ps.setString(1, account);
- ps.setString(2, Base64.getEncoder().encodeToString(newPassword));
- ps.setString(3, level);
- if (ps.executeUpdate() > 0)
- {
- System.out.println("Account " + account + " has been created or updated");
- }
- else
- {
- System.out.println("Account " + account + " does not exist");
- }
- }
- catch (Exception e)
- {
- System.out.println("There was error while adding/updating account:");
- System.out.println(e.getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement