forked from P0nk/Cosmic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Complete BCrypt migration * Remove unreachable exceptions
- Loading branch information
1 parent
5db3d11
commit cfbfbd5
Showing
5 changed files
with
52 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
/out | ||
*.onetoc2 | ||
.gradle/ | ||
bin/ | ||
|
||
# Eclipse m2e generated files | ||
# Eclipse Core | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
This file is part of the OdinMS Maple Story Server | ||
o This file is part of the OdinMS Maple Story Server | ||
Copyright (C) 2008 Patrick Huy <[email protected]> | ||
Matthias Butz <[email protected]> | ||
Jan Christian Meyer <[email protected]> | ||
|
@@ -21,6 +21,15 @@ | |
*/ | ||
package net.server.handlers.login; | ||
|
||
import java.sql.Connection; | ||
import java.sql.Date; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.sql.Timestamp; | ||
import java.util.Calendar; | ||
|
||
import client.Client; | ||
import client.DefaultDates; | ||
import config.YamlConfig; | ||
|
@@ -29,22 +38,9 @@ | |
import net.packet.InPacket; | ||
import net.server.Server; | ||
import net.server.coordinator.session.Hwid; | ||
import tools.BCrypt; | ||
import tools.HexTool; | ||
import tools.PacketCreator; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.sql.Connection; | ||
import java.sql.Date; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.sql.Timestamp; | ||
import java.util.Calendar; | ||
import utils.Crypto; | ||
|
||
public final class LoginPasswordHandler implements PacketHandler { | ||
|
||
|
@@ -53,12 +49,6 @@ public boolean validateState(Client c) { | |
return !c.isLoggedIn(); | ||
} | ||
|
||
private static String hashpwSHA512(String pwd) throws NoSuchAlgorithmException, UnsupportedEncodingException { | ||
MessageDigest digester = MessageDigest.getInstance("SHA-512"); | ||
digester.update(pwd.getBytes(StandardCharsets.UTF_8), 0, pwd.length()); | ||
return HexTool.toHexString(digester.digest()).replace(" ", "").toLowerCase(); | ||
} | ||
|
||
@Override | ||
public final void handlePacket(InPacket p, Client c) { | ||
String remoteHost = c.getRemoteAddress(); | ||
|
@@ -79,9 +69,9 @@ public final void handlePacket(InPacket p, Client c) { | |
|
||
if (YamlConfig.config.server.AUTOMATIC_REGISTER && loginok == 5) { | ||
try (Connection con = DatabaseConnection.getConnection(); | ||
PreparedStatement ps = con.prepareStatement("INSERT INTO accounts (name, password, birthday, tempban) VALUES (?, ?, ?, ?);", Statement.RETURN_GENERATED_KEYS)) { //Jayd: Added birthday, tempban | ||
ps.setString(1, login); | ||
ps.setString(2, YamlConfig.config.server.BCRYPT_MIGRATION ? BCrypt.hashpw(pwd, BCrypt.gensalt(12)) : hashpwSHA512(pwd)); | ||
PreparedStatement ps = con.prepareStatement("INSERT INTO accounts (name, password, birthday, tempban) VALUES (?, ?, ?, ?);", Statement.RETURN_GENERATED_KEYS)) { | ||
ps.setString(1, login); | ||
ps.setString(2, Crypto.hashpw(pwd, Crypto.gensalt(12))); | ||
ps.setDate(3, Date.valueOf(DefaultDates.getBirthday())); | ||
ps.setTimestamp(4, Timestamp.valueOf(DefaultDates.getTempban())); | ||
ps.executeUpdate(); | ||
|
@@ -90,7 +80,7 @@ public final void handlePacket(InPacket p, Client c) { | |
rs.next(); | ||
c.setAccID(rs.getInt(1)); | ||
} | ||
} catch (SQLException | NoSuchAlgorithmException | UnsupportedEncodingException e) { | ||
} catch (SQLException e) { | ||
c.setAccID(-1); | ||
e.printStackTrace(); | ||
} finally { | ||
|
@@ -101,7 +91,7 @@ public final void handlePacket(InPacket p, Client c) { | |
if (YamlConfig.config.server.BCRYPT_MIGRATION && (loginok <= -10)) { // -10 means migration to bcrypt, -23 means TOS wasn't accepted | ||
try (Connection con = DatabaseConnection.getConnection(); | ||
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET password = ? WHERE name = ?;")) { | ||
ps.setString(1, BCrypt.hashpw(pwd, BCrypt.gensalt(12))); | ||
ps.setString(1, Crypto.hashpw(pwd, Crypto.gensalt(12))); | ||
ps.setString(2, login); | ||
ps.executeUpdate(); | ||
} catch (SQLException e) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters