Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support changing password for nep6 wallet #1504

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1d0ef09
Merge pull request #13 from neo-project/master
Qiao-Jin Mar 19, 2020
33e0e26
Merge pull request #16 from neo-project/master
Qiao-Jin Mar 23, 2020
8988eda
Merge pull request #20 from neo-project/master
Qiao-Jin Mar 23, 2020
e67fab5
Support changing password for Nep6 wallet
Mar 23, 2020
f44b115
Code optimization
Mar 23, 2020
b724a0a
Merge branch 'master' into support_changing_password_for_Nep6_wallet
shargon Mar 23, 2020
8cb7f22
Opde optimization
Mar 24, 2020
7f47701
Merge branch 'master' into support_changing_password_for_Nep6_wallet
shargon Mar 24, 2020
dbeb6fa
Code optimization
Mar 24, 2020
6e5bf94
Merge branch 'support_changing_password_for_Nep6_wallet' of https://g…
Mar 24, 2020
0af889c
Merge branch 'master' into support_changing_password_for_Nep6_wallet
Qiao-Jin Mar 25, 2020
5b2c0bf
Merge branch 'master' into support_changing_password_for_Nep6_wallet
Qiao-Jin Mar 27, 2020
fcf102b
Merge branch 'master' into support_changing_password_for_Nep6_wallet
Qiao-Jin Mar 27, 2020
0488b66
Update src/neo/Wallets/NEP6/NEP6Account.cs
Qiao-Jin Mar 27, 2020
f787d23
Change Nep6 wallet and account password changing strategy
Mar 27, 2020
8a34e66
Follow comment standard
shargon Mar 27, 2020
45d129f
Fix indent
shargon Mar 27, 2020
acc09c1
Fix indent
shargon Mar 27, 2020
d8ac5e6
Fix indent
shargon Mar 27, 2020
586bec2
Follow comment standard
shargon Mar 27, 2020
f0020f2
Merge remote-tracking branch 'Qiao-Jin/support_changing_password_for_…
shargon Mar 27, 2020
53d082c
Code optimization
Mar 30, 2020
d856f7f
Update NEP6Wallet.cs
erikzhang Mar 30, 2020
be37eb4
Rename methods
Mar 30, 2020
598a94a
Merge branch 'master' into support_changing_password_for_Nep6_wallet
Qiao-Jin Mar 31, 2020
defb346
Code optimization
Mar 31, 2020
4f8af9a
Code optimization
Apr 1, 2020
c00c3d1
Code optimization
Apr 1, 2020
7ebdd05
Merge branch 'master' into support_changing_password_for_Nep6_wallet
shargon Apr 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/neo/Wallets/NEP6/NEP6Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Neo.Wallets.NEP6
internal class NEP6Account : WalletAccount
{
private readonly NEP6Wallet wallet;
private readonly string nep2key;
private string nep2key;
private KeyPair key;
public JObject Extra;

Expand Down Expand Up @@ -83,5 +83,30 @@ public bool VerifyPassword(string password)
return false;
}
}

public bool ChangePassword(string password_old, string password_new)
{
if (WatchOnly) return true;
shargon marked this conversation as resolved.
Show resolved Hide resolved
if (nep2key == null)
{
if (key == null)
{
return true;
}
}
else
{
if (!VerifyPassword(password_old))
{
return false;
}
else if (key == null)
{
key = wallet.DecryptKey(nep2key);
}
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
}
nep2key = key.Export(password_new, wallet.Scrypt.N, wallet.Scrypt.R, wallet.Scrypt.P);
return true;
}
}
}
16 changes: 16 additions & 0 deletions src/neo/Wallets/NEP6/NEP6Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,21 @@ public override bool VerifyPassword(string password)
}
}
}

public bool ChangePassword(string password_old, string password_new)
{
lock (accounts)
{
foreach (NEP6Account account in accounts.Values)
shargon marked this conversation as resolved.
Show resolved Hide resolved
{
if (!account.ChangePassword(password_old, password_new)) return false;
}
}
if (password != null)
{
password = password_new;
}
return true;
}
}
}
14 changes: 14 additions & 0 deletions tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ public void TestSetup()
_account = new NEP6Account(_wallet, _hash);
}

[TestMethod]
public void TestChangePassword()
{
_account = new NEP6Account(_wallet, _hash, _nep2);
_account.ChangePassword("b", "Satoshi").Should().BeTrue();
_account.Contract = new Contract();
_wallet.Unlock("Satoshi");
_account.ChangePassword("b", "Satoshi").Should().BeFalse();
_account.ChangePassword("Satoshi", "b").Should().BeTrue();
_account.VerifyPassword("b").Should().BeTrue();
_account.ChangePassword("b", "Satoshi").Should().BeTrue();
_wallet.Lock();
}

[TestMethod]
public void TestConstructorWithNep2Key()
{
Expand Down
12 changes: 12 additions & 0 deletions tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ public void TestCleanUp()
if (Directory.Exists(rootPath)) Directory.Delete(rootPath);
}

[TestMethod]
public void TestChangePassword()
{
uut.Unlock("123");
uut.CreateAccount(keyPair.PrivateKey);
uut.ChangePassword("456", "123").Should().BeFalse();
uut.ChangePassword("123", "456").Should().BeTrue();
uut.VerifyPassword("456").Should().BeTrue();
uut.ChangePassword("456", "123").Should().BeTrue();
uut.Lock();
}

[TestMethod]
public void TestConstructorWithPathAndName()
{
Expand Down