Skip to content

Commit

Permalink
Add abstract method Wallet.ChangePassword() (neo-project#1552)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored and Tommo-L committed Jun 22, 2020
1 parent 445918e commit ef9c798
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/neo/Wallets/NEP6/NEP6Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ public override bool VerifyPassword(string password)
}
}

public bool ChangePassword(string password_old, string password_new)
public override bool ChangePassword(string oldPassword, string newPassword)
{
bool succeed = true;
lock (accounts)
{
Parallel.ForEach(accounts.Values, (account, state) =>
{
if (!account.ChangePasswordPrepare(password_old, password_new))
if (!account.ChangePasswordPrepare(oldPassword, newPassword))
{
state.Stop();
succeed = false;
Expand All @@ -321,7 +321,7 @@ public bool ChangePassword(string password_old, string password_new)
foreach (NEP6Account account in accounts.Values)
account.ChangePasswordCommit();
if (password != null)
password = password_new;
password = newPassword;
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/neo/Wallets/SQLite/UserWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ private void BuildDatabase()
}
}

public bool ChangePassword(string password_old, string password_new)
public override bool ChangePassword(string oldPassword, string newPassword)
{
if (!VerifyPassword(password_old)) return false;
byte[] passwordKey = password_new.ToAesKey();
if (!VerifyPassword(oldPassword)) return false;
byte[] passwordKey = newPassword.ToAesKey();
try
{
SaveStoredData("PasswordHash", passwordKey.Concat(salt).ToArray().Sha256());
Expand Down
1 change: 1 addition & 0 deletions src/neo/Wallets/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public abstract class Wallet
public abstract string Name { get; }
public abstract Version Version { get; }

public abstract bool ChangePassword(string oldPassword, string newPassword);
public abstract bool Contains(UInt160 scriptHash);
public abstract WalletAccount CreateAccount(byte[] privateKey);
public abstract WalletAccount CreateAccount(Contract contract, KeyPair key = null);
Expand Down
5 changes: 5 additions & 0 deletions tests/neo.UnitTests/Wallets/UT_Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ internal class MyWallet : Wallet

Dictionary<UInt160, WalletAccount> accounts = new Dictionary<UInt160, WalletAccount>();

public override bool ChangePassword(string oldPassword, string newPassword)
{
throw new NotImplementedException();
}

public override bool Contains(UInt160 scriptHash)
{
return accounts.ContainsKey(scriptHash);
Expand Down

0 comments on commit ef9c798

Please sign in to comment.