@Test public void setPassword() { List<Account> accounts = this.accountService.createAccount(1, "").getData(); Account account = accounts.get(0); accountBaseService.setPassword(account.getAddress().toString(),"nuls123456"); Account acc = accountService.getAccount(account.getAddress()).getData(); try { assertTrue(acc.unlock("nuls123456")); assertArrayEquals(acc.getPriKey(), account.getPriKey()); } catch (NulsException e) { e.printStackTrace(); } }
public Result setPassword(String address, String password) { if (!AddressTool.validAddress(address)) { return Result.getFailed(AccountErrorCode.ADDRESS_ERROR); } if (StringUtils.isBlank(password)) { return Result.getFailed(AccountErrorCode.NULL_PARAMETER); } if (!StringUtils.validPassword(password)) { return Result.getFailed(AccountErrorCode.PASSWORD_FORMAT_WRONG); } Account account = accountService.getAccount(address).getData(); if (null == account) { return Result.getFailed(AccountErrorCode.ACCOUNT_NOT_EXIST); } if (account.isEncrypted()) { return Result.getFailed(AccountErrorCode.ACCOUNT_IS_ALREADY_ENCRYPTED); } try { account.encrypt(password); Result result = accountStorageService.updateAccount(new AccountPo(account)); if (result.isFailed()) { return Result.getFailed(AccountErrorCode.FAILED); } accountCacheService.localAccountMaps.put(account.getAddress().getBase58(), account); } catch (NulsException e) { Log.error(e); return Result.getFailed(AccountErrorCode.FAILED); } return Result.getSuccess().setData(true); }
AccountBaseService { public Result setPassword(String address, String password) { if (!AddressTool.validAddress(address)) { return Result.getFailed(AccountErrorCode.ADDRESS_ERROR); } if (StringUtils.isBlank(password)) { return Result.getFailed(AccountErrorCode.NULL_PARAMETER); } if (!StringUtils.validPassword(password)) { return Result.getFailed(AccountErrorCode.PASSWORD_FORMAT_WRONG); } Account account = accountService.getAccount(address).getData(); if (null == account) { return Result.getFailed(AccountErrorCode.ACCOUNT_NOT_EXIST); } if (account.isEncrypted()) { return Result.getFailed(AccountErrorCode.ACCOUNT_IS_ALREADY_ENCRYPTED); } try { account.encrypt(password); Result result = accountStorageService.updateAccount(new AccountPo(account)); if (result.isFailed()) { return Result.getFailed(AccountErrorCode.FAILED); } accountCacheService.localAccountMaps.put(account.getAddress().getBase58(), account); } catch (NulsException e) { Log.error(e); return Result.getFailed(AccountErrorCode.FAILED); } return Result.getSuccess().setData(true); } }
AccountBaseService { public Result setPassword(String address, String password) { if (!AddressTool.validAddress(address)) { return Result.getFailed(AccountErrorCode.ADDRESS_ERROR); } if (StringUtils.isBlank(password)) { return Result.getFailed(AccountErrorCode.NULL_PARAMETER); } if (!StringUtils.validPassword(password)) { return Result.getFailed(AccountErrorCode.PASSWORD_FORMAT_WRONG); } Account account = accountService.getAccount(address).getData(); if (null == account) { return Result.getFailed(AccountErrorCode.ACCOUNT_NOT_EXIST); } if (account.isEncrypted()) { return Result.getFailed(AccountErrorCode.ACCOUNT_IS_ALREADY_ENCRYPTED); } try { account.encrypt(password); Result result = accountStorageService.updateAccount(new AccountPo(account)); if (result.isFailed()) { return Result.getFailed(AccountErrorCode.FAILED); } accountCacheService.localAccountMaps.put(account.getAddress().getBase58(), account); } catch (NulsException e) { Log.error(e); return Result.getFailed(AccountErrorCode.FAILED); } return Result.getSuccess().setData(true); }  }
AccountBaseService { public Result setPassword(String address, String password) { if (!AddressTool.validAddress(address)) { return Result.getFailed(AccountErrorCode.ADDRESS_ERROR); } if (StringUtils.isBlank(password)) { return Result.getFailed(AccountErrorCode.NULL_PARAMETER); } if (!StringUtils.validPassword(password)) { return Result.getFailed(AccountErrorCode.PASSWORD_FORMAT_WRONG); } Account account = accountService.getAccount(address).getData(); if (null == account) { return Result.getFailed(AccountErrorCode.ACCOUNT_NOT_EXIST); } if (account.isEncrypted()) { return Result.getFailed(AccountErrorCode.ACCOUNT_IS_ALREADY_ENCRYPTED); } try { account.encrypt(password); Result result = accountStorageService.updateAccount(new AccountPo(account)); if (result.isFailed()) { return Result.getFailed(AccountErrorCode.FAILED); } accountCacheService.localAccountMaps.put(account.getAddress().getBase58(), account); } catch (NulsException e) { Log.error(e); return Result.getFailed(AccountErrorCode.FAILED); } return Result.getSuccess().setData(true); }  Result setRemark(String address, String remark); Result getPrivateKey(String address, String password); Result getAllPrivateKey(String password); Result getAllPrivateKey(); Result setPassword(String address, String password); Result changePassword(String address, String oldPassword, String newPassword); }
AccountBaseService { public Result setPassword(String address, String password) { if (!AddressTool.validAddress(address)) { return Result.getFailed(AccountErrorCode.ADDRESS_ERROR); } if (StringUtils.isBlank(password)) { return Result.getFailed(AccountErrorCode.NULL_PARAMETER); } if (!StringUtils.validPassword(password)) { return Result.getFailed(AccountErrorCode.PASSWORD_FORMAT_WRONG); } Account account = accountService.getAccount(address).getData(); if (null == account) { return Result.getFailed(AccountErrorCode.ACCOUNT_NOT_EXIST); } if (account.isEncrypted()) { return Result.getFailed(AccountErrorCode.ACCOUNT_IS_ALREADY_ENCRYPTED); } try { account.encrypt(password); Result result = accountStorageService.updateAccount(new AccountPo(account)); if (result.isFailed()) { return Result.getFailed(AccountErrorCode.FAILED); } accountCacheService.localAccountMaps.put(account.getAddress().getBase58(), account); } catch (NulsException e) { Log.error(e); return Result.getFailed(AccountErrorCode.FAILED); } return Result.getSuccess().setData(true); }  Result setRemark(String address, String remark); Result getPrivateKey(String address, String password); Result getAllPrivateKey(String password); Result getAllPrivateKey(); Result setPassword(String address, String password); Result changePassword(String address, String oldPassword, String newPassword);  }