Skip to content

Commit

Permalink
如果是嵌入模式且是安全模式就不需要验证密码,此时可以重置密码 #223
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Jun 29, 2024
1 parent c863f44 commit f0d7394
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static JdbcConnection getConnectionSync(ConnectionInfo ci) {
private String port = Constants.DEFAULT_TCP_PORT + "";
private String database = "lealone";
private boolean embedded;
private boolean safeMode;

public static void main(String[] args) {
LealoneClient client = new LealoneClient(args);
Expand Down Expand Up @@ -133,6 +134,8 @@ private void run() throws Exception {
listMode = true;
} else if (arg.equals("-embed")) {
embedded = true;
} else if (arg.equals("-safeMode")) {
safeMode = true;
} else if (arg.equals("-client") || arg.equals("-debug")) {
continue;
} else {
Expand Down Expand Up @@ -207,6 +210,7 @@ protected ConnectionInfo getConnectionInfo() throws SQLException {
// 交互式命令行客户端用阻塞IO更快
if (ci.isRemote())
ci.setNetFactoryName(BioNetFactory.NAME);
ci.setSafeMode(safeMode);
return ci;
}

Expand Down
10 changes: 10 additions & 0 deletions lealone-common/src/main/java/com/lealone/db/ConnectionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -818,4 +818,14 @@ public Scheduler getScheduler() {
public void setScheduler(Scheduler scheduler) {
this.scheduler = scheduler;
}

private boolean safeMode;

public boolean isSafeMode() {
return safeMode;
}

public void setSafeMode(boolean safeMode) {
this.safeMode = safeMode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,15 @@ private User validateUser(Database database, ConnectionInfo ci) {
ci.getFilePasswordHash())) {
user = database.findUser(null, ci.getUserName());
if (user != null) {
Mode mode = Mode.getInstance(
ci.getProperty(DbSetting.MODE.name(), Mode.getDefaultMode().getName()));
if (!user.validateUserPasswordHash(ci.getUserPasswordHash(), ci.getSalt(), mode)) {
user = null;
} else {
database.setLastConnectionInfo(ci);
// 如果是嵌入模式且是安全模式就不需要验证密码,此时可以重置密码
if (!(ci.isEmbedded() && ci.isSafeMode())) {
Mode mode = Mode.getInstance(
ci.getProperty(DbSetting.MODE.name(), Mode.getDefaultMode().getName()));
if (!user.validateUserPasswordHash(ci.getUserPasswordHash(), ci.getSalt(), mode)) {
user = null;
} else {
database.setLastConnectionInfo(ci);
}
}
}
}
Expand Down

0 comments on commit f0d7394

Please sign in to comment.