diff --git a/core/src/main/java/bisq/core/api/CoreAccountService.java b/core/src/main/java/bisq/core/api/CoreAccountService.java index f8cce7cb14..5d916ae679 100644 --- a/core/src/main/java/bisq/core/api/CoreAccountService.java +++ b/core/src/main/java/bisq/core/api/CoreAccountService.java @@ -35,6 +35,9 @@ import java.util.List; import java.util.function.Consumer; import javax.inject.Inject; import javax.inject.Singleton; + +import org.apache.commons.lang3.StringUtils; + import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -111,13 +114,13 @@ public class CoreAccountService { } } - public void changePassword(String password) { + public void changePassword(String oldPassword, String newPassword) { if (!isAccountOpen()) throw new IllegalStateException("Cannot change password on unopened account"); - String oldPassword = this.password; - keyStorage.saveKeyRing(keyRing, oldPassword, password); - this.password = password; + if (!StringUtils.equals(this.password, oldPassword)) throw new IllegalStateException("Incorrect password"); + keyStorage.saveKeyRing(keyRing, oldPassword, newPassword); + this.password = newPassword; synchronized (listeners) { - for (AccountServiceListener listener : listeners) listener.onPasswordChanged(oldPassword, password); + for (AccountServiceListener listener : listeners) listener.onPasswordChanged(oldPassword, newPassword); } } diff --git a/core/src/main/java/bisq/core/api/CoreApi.java b/core/src/main/java/bisq/core/api/CoreApi.java index ac9d369a02..7278df2d73 100644 --- a/core/src/main/java/bisq/core/api/CoreApi.java +++ b/core/src/main/java/bisq/core/api/CoreApi.java @@ -169,8 +169,8 @@ public class CoreApi { return appStartupState.isApplicationFullyInitialized(); } - public void changePassword(String password) { - coreAccountService.changePassword(password); + public void changePassword(String oldPassword, String newPassword) { + coreAccountService.changePassword(oldPassword, newPassword); } public void closeAccount() { diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcAccountService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcAccountService.java index 6f2111762b..5c997ef815 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcAccountService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcAccountService.java @@ -145,7 +145,7 @@ public class GrpcAccountService extends AccountImplBase { @Override public void changePassword(ChangePasswordRequest req, StreamObserver responseObserver) { try { - coreApi.changePassword(req.getPassword()); + coreApi.changePassword(req.getOldPassword(), req.getNewPassword()); var reply = ChangePasswordReply.newBuilder().build(); responseObserver.onNext(reply); responseObserver.onCompleted(); diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index 1418e30ca9..6651f7729e 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -119,7 +119,8 @@ message IsAppInitializedReply { } message ChangePasswordRequest { - string password = 1; + string old_password = 1; + string new_password = 2; } message ChangePasswordReply {