Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
#30: Add way to change password.
Browse files Browse the repository at this point in the history
  • Loading branch information
nschum committed Dec 18, 2013
2 parents a285101 + 209b913 commit 5614bce
Show file tree
Hide file tree
Showing 33 changed files with 695 additions and 57 deletions.
2 changes: 1 addition & 1 deletion BitcoinKit
Submodule BitcoinKit updated 35 files
+0 −3 .gitmodules
+0 −0 BitcoinJKit/HIBitcoinErrorCodes.h
+0 −0 BitcoinJKit/HIBitcoinErrorCodes.m
+10 −0 BitcoinJKit/HIBitcoinManager.h
+22 −2 BitcoinJKit/HIBitcoinManager.m
+4 −6 BitcoinJKit/HILogger.h
+0 −2 BitcoinJKit/en.lproj/InfoPlist.strings
+26 −0 BitcoinJKit/java/bitcoinkit/src/main/java/com/hive/bitcoinkit/BitcoinManager.java
+17 −1,177 BitcoinKit.xcodeproj/project.pbxproj
+0 −30 BitcoinKit/BitcoinKit-Info.plist
+0 −7 BitcoinKit/BitcoinKit-Prefix.pch
+0 −9 BitcoinKit/BitcoinKit.h
+0 −695 BitcoinKit/HIBitcoinManager.mm
+0 −2 BitcoinKit/en.lproj/InfoPlist.strings
+1 −0 DemoApp/HIBitcoinJKitDemo/HIAppDelegate.h
+264 −0 DemoApp/HIBitcoinJKitDemo/HIAppDelegate.m
+0 −2 DemoApp/HIBitcoinJKitDemo/HIBitcoinJKitDemo-Prefix.pch
+2 −0 DemoApp/HIBitcoinJKitDemo/HISendWindowController.h
+27 −17 DemoApp/HIBitcoinJKitDemo/HISendWindowController.m
+0 −0 DemoApp/HIBitcoinJKitDemo/HISendWindowController.xib
+0 −0 DemoApp/HIBitcoinJKitDemo/en.lproj/MainMenu.xib
+22 −213 DemoApp/HIBitcoinKitDemo.xcodeproj/project.pbxproj
+0 −214 DemoApp/HIBitcoinKitDemo/HIAppDelegate.m
+0 −34 DemoApp/HIBitcoinKitDemo/HIBitcoinKitDemo-Info.plist
+0 −7 DemoApp/HIBitcoinKitDemo/HIBitcoinKitDemo-Prefix.pch
+0 −29 DemoApp/HIBitcoinKitDemo/en.lproj/Credits.rtf
+0 −2 DemoApp/HIBitcoinKitDemo/en.lproj/InfoPlist.strings
+0 −14 DemoApp/HIBitcoinKitDemo/main.m
+0 −6 bitcoin/bitcoin-Prefix.pch
+0 −25 bitcoin/bitcoin.cp
+0 −23 bitcoin/bitcoin.h
+0 −19 bitcoin/bitcoinPriv.h
+0 −4 bitcoin/bitcoinProj.xcconfig
+0 −10 bitcoin/bitcoinTarget.xcconfig
+0 −1 bitcoind
50 changes: 19 additions & 31 deletions Hive.xcodeproj/project.pbxproj
Expand Up @@ -15,6 +15,8 @@
1AA10AB8CB13510790BD9A6D /* HIPasswordHolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 1AA10711079E121245A12DED /* HIPasswordHolder.m */; };
1AA10B3C94C377F4EF024D41 /* HIProfileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1AA1013FB9712D7B30A91BFB /* HIProfileViewController.m */; };
1AA10ECC39D33A1362882EB2 /* HIProfileViewController.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1AA108BDEC523213EF9B8309 /* HIProfileViewController.strings */; };
24178E301861005100A73D4E /* HIPasswordChangeWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24178E2E1861005100A73D4E /* HIPasswordChangeWindowController.m */; };
24178E311861005100A73D4E /* HIPasswordChangeWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24178E2F1861005100A73D4E /* HIPasswordChangeWindowController.xib */; };
244303BA1856712000AD59B8 /* HIPasswordInputViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 244303B81856712000AD59B8 /* HIPasswordInputViewController.m */; };
244303BB1856712000AD59B8 /* HIPasswordInputViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 244303B91856712000AD59B8 /* HIPasswordInputViewController.xib */; };
2478B8D3184A80A400BA2C35 /* HIFeeDetailsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2478B8D1184A80A400BA2C35 /* HIFeeDetailsViewController.m */; };
Expand Down Expand Up @@ -194,20 +196,6 @@
remoteGlobalIDString = D958B09C17A29B0500B0EDD5;
remoteInfo = BitcoinJKit;
};
D91FE80C1793FEFC001B37D8 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = D91FE8071793FEFC001B37D8 /* BitcoinKit.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = D91FE4EE178EB1F1001B37D8;
remoteInfo = BitcoinKit;
};
D91FE80E1793FEFC001B37D8 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = D91FE8071793FEFC001B37D8 /* BitcoinKit.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = D91FE6FD178EB8C5001B37D8;
remoteInfo = bitcoin;
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -242,6 +230,9 @@
1AA10C583F128C0BCD84C878 /* HIExchangeRateService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HIExchangeRateService.h; sourceTree = "<group>"; };
1AA10F3E7660E657A58361D9 /* HIProfileViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HIProfileViewController.h; sourceTree = "<group>"; };
1EFBACBE45EB458A8ED83785 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
24178E2D1861005100A73D4E /* HIPasswordChangeWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HIPasswordChangeWindowController.h; sourceTree = "<group>"; };
24178E2E1861005100A73D4E /* HIPasswordChangeWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HIPasswordChangeWindowController.m; sourceTree = "<group>"; };
24178E2F1861005100A73D4E /* HIPasswordChangeWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HIPasswordChangeWindowController.xib; sourceTree = "<group>"; };
244303B71856712000AD59B8 /* HIPasswordInputViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HIPasswordInputViewController.h; sourceTree = "<group>"; };
244303B81856712000AD59B8 /* HIPasswordInputViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HIPasswordInputViewController.m; sourceTree = "<group>"; };
244303B91856712000AD59B8 /* HIPasswordInputViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HIPasswordInputViewController.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -432,7 +423,7 @@
5832C539180ECF46002A673F /* de */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = de; path = de.lproj/MainMenu.xib; sourceTree = "<group>"; };
5832C53B180ECF46002A673F /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/InfoPlist.strings; sourceTree = "<group>"; };
5832C53C180ECF46002A673F /* de */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = "<group>"; };
58357A3B186068A70077B717 /* 2013121701.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = file; path = 2013121701.xcdatamodel; sourceTree = "<group>"; };
58357A3B186068A70077B717 /* 2013121701.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = 2013121701.xcdatamodel; sourceTree = "<group>"; };
585A8B2318576F020096888C /* HIDatabaseManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HIDatabaseManager.h; sourceTree = "<group>"; };
585A8B2418576F020096888C /* HIDatabaseManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HIDatabaseManager.m; sourceTree = "<group>"; };
585FFF201815374B005BCF73 /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/HIApplicationsViewController.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1208,6 +1199,16 @@
name = HIProfileViewController;
sourceTree = "<group>";
};
24178E1D1860FEC300A73D4E /* HIPasswordChangeWindowController */ = {
isa = PBXGroup;
children = (
24178E2D1861005100A73D4E /* HIPasswordChangeWindowController.h */,
24178E2E1861005100A73D4E /* HIPasswordChangeWindowController.m */,
24178E2F1861005100A73D4E /* HIPasswordChangeWindowController.xib */,
);
name = HIPasswordChangeWindowController;
sourceTree = "<group>";
};
244303B2185670DB00AD59B8 /* HIPasswordInputViewController */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1362,8 +1363,6 @@
D91FE8081793FEFC001B37D8 /* Products */ = {
isa = PBXGroup;
children = (
D91FE80D1793FEFC001B37D8 /* BitcoinKit.framework */,
D91FE80F1793FEFC001B37D8 /* bitcoin.a */,
D901F4F517B272CE0071780D /* BitcoinJKit.framework */,
);
name = Products;
Expand Down Expand Up @@ -1626,6 +1625,7 @@
586059F918041AD600FD9C2A /* HINavigationController.h */,
586059FA18041AD600FD9C2A /* HINavigationController.m */,
D94815EA17D4CD23006A0312 /* HINewContactViewController */,
24178E1D1860FEC300A73D4E /* HIPasswordChangeWindowController */,
244303B2185670DB00AD59B8 /* HIPasswordInputViewController */,
1AA103C2AED626BF5E200D14 /* HIProfileViewController */,
58A2A7E817D8783D0001464A /* HISendBitcoinsWindowController */,
Expand Down Expand Up @@ -1780,20 +1780,6 @@
remoteRef = D901F4F417B272CE0071780D /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
D91FE80D1793FEFC001B37D8 /* BitcoinKit.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = BitcoinKit.framework;
remoteRef = D91FE80C1793FEFC001B37D8 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
D91FE80F1793FEFC001B37D8 /* bitcoin.a */ = {
isa = PBXReferenceProxy;
fileType = "compiled.mach-o.dylib";
path = bitcoin.a;
remoteRef = D91FE80E1793FEFC001B37D8 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
Expand Down Expand Up @@ -1832,6 +1818,7 @@
58A37A9E180D7AFC00CFCDE3 /* HIMainWindowController.xib in Resources */,
58605A4018041D0A00FD9C2A /* avatar-empty.pdf in Resources */,
582C7DA6185219A000126C10 /* HIDebuggingToolsWindowController.xib in Resources */,
24178E311861005100A73D4E /* HIPasswordChangeWindowController.xib in Resources */,
58605A4118041D0A00FD9C2A /* bg-sidebar.pdf in Resources */,
58A37ACD180D995000CFCDE3 /* HIContactsViewController.strings in Resources */,
58605A4218041D0A00FD9C2A /* button__inset.pdf in Resources */,
Expand Down Expand Up @@ -1977,6 +1964,7 @@
58605A6818041DFC00FD9C2A /* NPZipFileHeader.m in Sources */,
58605A6918041DFC00FD9C2A /* NPZipHeader.m in Sources */,
5860D3FF180455B900BD852C /* HIApplicationsManager.m in Sources */,
24178E301861005100A73D4E /* HIPasswordChangeWindowController.m in Sources */,
589064B7180596B80082BE5C /* HIEditableImageView.m in Sources */,
1AA10A016757DBB9BE7808C5 /* HIExchangeRateService.m in Sources */,
1AA10B3C94C377F4EF024D41 /* HIProfileViewController.m in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Hive/Backend/BCClient.h
Expand Up @@ -35,6 +35,10 @@
- (void)createWalletWithPassword:(HIPasswordHolder *)password
error:(NSError **)error;

- (void)changeWalletPassword:(HIPasswordHolder *)fromPassword
toPassword:(HIPasswordHolder *)toPassword
error:(NSError **)error;

- (void)sendBitcoins:(uint64)amount
toHash:(NSString *)hash
password:(HIPasswordHolder *)password
Expand Down
9 changes: 9 additions & 0 deletions Hive/Backend/BCClient.m
Expand Up @@ -141,6 +141,15 @@ - (void)createWalletWithPassword:(HIPasswordHolder *)password
[[HIBitcoinManager defaultManager] createWalletWithPassword:password.data error:error];
}

- (void)changeWalletPassword:(HIPasswordHolder *)fromPassword
toPassword:(HIPasswordHolder *)toPassword
error:(NSError **)error {
HILogInfo(@"Changing wallet password...");
[[HIBitcoinManager defaultManager] changeWalletPassword:fromPassword.data
toPassword:toPassword.data
error:error];
}

- (void)torStarted:(NSNotification *)notification {
[HITorManager defaultManager].torRouting = YES;
}
Expand Down
15 changes: 15 additions & 0 deletions Hive/Controllers/HIPasswordChangeWindowController.h
@@ -0,0 +1,15 @@
//
// HIPasswordChangeWindowController.h
// Hive
//
// Created by Nikolaj Schumacher on 2013-12-17.
// Copyright (c) 2013 Hive Developers. All rights reserved.
//

@class HIPasswordHolder;

@interface HIPasswordChangeWindowController : NSWindowController

- (void)resetInput;

@end
152 changes: 152 additions & 0 deletions Hive/Controllers/HIPasswordChangeWindowController.m
@@ -0,0 +1,152 @@
//
// HIPasswordChangeWindowController.m
// Hive
//
// Created by Nikolaj Schumacher on 2013-12-17.
// Copyright (c) 2013 Hive Developers. All rights reserved.
//

#import "HIPasswordChangeWindowController.h"
#import "HIPasswordHolder.h"
#import "BCClient.h"
#import "NSWindow+HIShake.h"

#import <BitcoinJKit/HIBitcoinErrorCodes.h>

/*
We don't want the password sitting there while the user walks away.
*/
static const NSTimeInterval IDLE_RESET_DELAY = 30.0;

@interface HIPasswordChangeWindowController ()

@property(nonatomic, strong) IBOutlet NSSecureTextField *passwordField;
@property(nonatomic, strong) IBOutlet NSSecureTextField *updatedPasswordField;
@property(nonatomic, strong) IBOutlet NSSecureTextField *repeatedPasswordField;

@property (nonatomic, assign) BOOL submitButtonEnabled;

@end

@implementation HIPasswordChangeWindowController

- (id)init {
return [self initWithWindowNibName:[self className]];
}

- (IBAction)showWindow:(id)sender {
[super showWindow:sender];

[self resetInput];

BOOL oldPasswordExists = [BCClient sharedClient].isWalletPasswordProtected;
[self.passwordField setEnabled:oldPasswordExists];
[(oldPasswordExists ? self.passwordField : self.updatedPasswordField) becomeFirstResponder];
}

- (IBAction)submit:(id)sender {
@autoreleasepool {
HIPasswordHolder *passwordHolder =
self.passwordField.stringValue.length > 0
? [[HIPasswordHolder alloc] initWithString:self.passwordField.stringValue] : nil;
HIPasswordHolder *changedPasswordHolder =
[[HIPasswordHolder alloc] initWithString:self.updatedPasswordField.stringValue];
@try {
NSError *error = nil;
[[BCClient sharedClient] changeWalletPassword:passwordHolder
toPassword:changedPasswordHolder
error:&error];
if (error) {
if (error.code == kHIBitcoinManagerWrongPassword) {
[self.window hiShake];
[self.passwordField becomeFirstResponder];
} else {
[[NSAlert alertWithError:error] runModal];
}
} else {
[self close];
}
} @finally {
[passwordHolder clear];
[changedPasswordHolder clear];
}
}
}

- (void)resetInput {
self.passwordField.stringValue = @"";
self.updatedPasswordField.stringValue = @"";
self.repeatedPasswordField.stringValue = @"";
[self updateIdleResetDelay];
}

- (void)close {
[self resetInput];
[super close];
}

#pragma mark - NSTextFieldDelegate

- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector {
if (commandSelector == @selector(insertNewline:)) {
if (control == self.passwordField) {
[self.updatedPasswordField becomeFirstResponder];
} else if (control == self.updatedPasswordField) {
[self.repeatedPasswordField becomeFirstResponder];
} else if (self.submitButtonEnabled) {
[self submit:control];
} else {
[self updateValidation];
[self.repeatedPasswordField becomeFirstResponder];
}
return YES;
} else {
return NO;
}
}

- (void)controlTextDidChange:(NSNotification *)notification {
// TODO: Do we impose password complexity rules?
BOOL passwordsEqual = [self arePasswordsEqual];

self.submitButtonEnabled = (!self.passwordField.isEnabled || self.passwordField.stringValue.length > 0)
&& self.updatedPasswordField.stringValue.length > 0 && passwordsEqual;

if (self.repeatedPasswordField != notification.object) {
[self updateValidation];
} else if (passwordsEqual) {
[self clearValidationProblems];
}
[self updateIdleResetDelay];
}

- (BOOL)arePasswordsEqual {
return [self.updatedPasswordField.stringValue isEqualToString:self.repeatedPasswordField.stringValue];
}

- (void)controlTextDidEndEditing:(NSNotification *)obj {
[self updateValidation];
}

- (void)updateValidation {
if ([self arePasswordsEqual]) {
[self clearValidationProblems];
} else if (self.repeatedPasswordField.stringValue.length > 0) {
self.repeatedPasswordField.backgroundColor = [[NSColor redColor] colorWithAlphaComponent:0.25];
}
}

- (void)clearValidationProblems {
self.repeatedPasswordField.backgroundColor = [NSColor clearColor];
}

- (void)updateIdleResetDelay {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(resetInput) object:nil];
if (self.passwordField.stringValue.length > 0) {
[self performSelector:@selector(resetInput)
withObject:nil
afterDelay:IDLE_RESET_DELAY];
}
}

@end

0 comments on commit 5614bce

Please sign in to comment.