Added check box to password entry view to allow "no password" as currently only empty strings were allowed

This commit is contained in:
michael starke
2013-11-23 21:11:56 +01:00
parent 503acbad42
commit 77461a12e2
4 changed files with 63 additions and 49 deletions

View File

@@ -7,6 +7,7 @@
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPPasswordInputController">
<connections>
<outlet property="enablePasswordCheckBox" destination="d8O-Ha-rrS" id="2AI-e9-sph"/>
<outlet property="errorImage" destination="262" id="291"/>
<outlet property="errorImageView" destination="262" id="294"/>
<outlet property="errorInfoTextField" destination="268" id="293"/>
@@ -46,15 +47,6 @@ DQ
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="31">
<rect key="frame" x="99" y="143" width="62" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Password" id="32">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<pathControl verticalHuggingPriority="750" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="241">
<rect key="frame" x="164" y="109" width="197" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
@@ -114,14 +106,20 @@ DQ
<action selector="resetKeyFile:" target="-2" id="2Zh-0g-L0i"/>
</connections>
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="d8O-Ha-rrS">
<rect key="frame" x="81" y="143" width="80" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Password" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="IU9-5u-jn9">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
</subviews>
<constraints>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="2" secondAttribute="bottom" constant="20" symbolic="YES" id="122"/>
<constraint firstItem="31" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="1" secondAttribute="leading" constant="20" symbolic="YES" id="124"/>
<constraint firstItem="262" firstAttribute="top" relation="greaterThanOrEqual" secondItem="1" secondAttribute="top" constant="20" symbolic="YES" id="276"/>
<constraint firstAttribute="centerX" secondItem="262" secondAttribute="centerX" id="286"/>
<constraint firstAttribute="centerY" secondItem="338" secondAttribute="centerY" id="386"/>
<constraint firstItem="31" firstAttribute="baseline" secondItem="338" secondAttribute="baseline" id="396"/>
<constraint firstItem="338" firstAttribute="top" secondItem="268" secondAttribute="bottom" constant="8" symbolic="YES" id="400"/>
<constraint firstItem="268" firstAttribute="top" secondItem="262" secondAttribute="bottom" constant="8" symbolic="YES" id="402"/>
<constraint firstItem="408" firstAttribute="top" secondItem="338" secondAttribute="top" id="411"/>
@@ -132,13 +130,16 @@ DQ
<constraint firstItem="241" firstAttribute="top" secondItem="338" secondAttribute="bottom" constant="8" symbolic="YES" id="476"/>
<constraint firstItem="17" firstAttribute="bottom" secondItem="241" secondAttribute="bottom" id="478"/>
<constraint firstAttribute="centerX" secondItem="338" secondAttribute="centerX" id="479"/>
<constraint firstItem="338" firstAttribute="leading" secondItem="31" secondAttribute="trailing" constant="8" symbolic="YES" id="484"/>
<constraint firstItem="2" firstAttribute="top" secondItem="241" secondAttribute="bottom" constant="20" symbolic="YES" id="485"/>
<constraint firstItem="486" firstAttribute="baseline" secondItem="17" secondAttribute="baseline" id="488"/>
<constraint firstItem="486" firstAttribute="leading" secondItem="241" secondAttribute="trailing" constant="8" symbolic="YES" id="489"/>
<constraint firstItem="486" firstAttribute="leading" secondItem="408" secondAttribute="leading" id="490"/>
<constraint firstItem="408" firstAttribute="trailing" secondItem="486" secondAttribute="trailing" id="492"/>
<constraint firstItem="2" firstAttribute="trailing" secondItem="486" secondAttribute="trailing" id="496"/>
<constraint firstItem="408" firstAttribute="leading" secondItem="338" secondAttribute="trailing" constant="8" symbolic="YES" id="7qE-8F-QgB"/>
<constraint firstItem="338" firstAttribute="leading" secondItem="d8O-Ha-rrS" secondAttribute="trailing" constant="8" symbolic="YES" id="KYs-Ia-SVl"/>
<constraint firstItem="d8O-Ha-rrS" firstAttribute="centerY" secondItem="338" secondAttribute="centerY" id="kgB-jV-OGy"/>
<constraint firstItem="d8O-Ha-rrS" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="1" secondAttribute="leading" constant="20" symbolic="YES" id="vxq-YP-UhR"/>
</constraints>
</customView>
</objects>

View File

@@ -235,7 +235,8 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
BOOL isUnlocked = (nil != self.tree);
if(isUnlocked) {
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidUnlockDatabaseNotification object:self];
if([password length] > 0 && self.isAllowedToStoreKeyFile) {
/* Make sure to only store */
if(self.compositeKey.hasPassword && self.isAllowedToStoreKeyFile) {
[self _storeKeyURL:keyFileURL];
}
}

View File

@@ -23,8 +23,10 @@
@property (weak) IBOutlet NSImageView *errorImageView;
@property (weak) IBOutlet NSTextField *errorInfoTextField;
@property (weak) IBOutlet NSButton *togglePasswordButton;
@property (weak) IBOutlet NSButton *enablePasswordCheckBox;
@property (assign) BOOL showPassword;
@property (assign) BOOL enablePassword;
@end
@@ -38,6 +40,7 @@
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self) {
_enablePassword = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_selectKeyURL) name:MPDocumentDidChangeStoredKeyFilesSettings object:nil];
}
return self;
@@ -52,6 +55,9 @@
[self.errorImageView setImage:[NSImage imageNamed:NSImageNameCaution]];
[self.passwordTextField bind:@"showPassword" toObject:self withKeyPath:@"showPassword" options:nil];
[self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:@"showPassword" options:nil];
[self.enablePasswordCheckBox bind:NSValueBinding toObject:self withKeyPath:@"enablePassword" options:nil];
[self.togglePasswordButton bind:NSEnabledBinding toObject:self withKeyPath:@"enablePassword" options:nil];
[self.passwordTextField bind:NSEnabledBinding toObject:self withKeyPath:@"enablePassword" options:nil];
[self _reset];
}
@@ -70,7 +76,9 @@
MPDocument *document = [[self windowController] document];
if(document) {
NSError *error = nil;
if(![document unlockWithPassword:[self.passwordTextField stringValue]
/* No password is different than an empty password */
NSString *password = self.enablePassword ? [self.passwordTextField stringValue] : nil;
if(![document unlockWithPassword:password
keyFileURL:[self.keyPathControl URL]
error:&error]) {
[self _showError:error];
@@ -84,6 +92,7 @@
- (void)_reset {
self.showPassword = NO;
self.enablePassword = YES;
[self.passwordTextField setStringValue:@""];
[self.errorInfoTextField setHidden:YES];
[self.errorImageView setHidden:YES];

View File

@@ -21,26 +21,14 @@
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" wantsToBeColor="NO" visibleAtLaunch="NO" animationBehavior="default" id="1">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="349" height="212"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1028"/>
<rect key="contentRect" x="196" y="240" width="335" height="212"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1058"/>
<view key="contentView" id="2">
<rect key="frame" x="0.0" y="0.0" width="349" height="212"/>
<rect key="frame" x="0.0" y="0.0" width="335" height="212"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3">
<rect key="frame" x="18" y="147" width="66" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<constraints>
<constraint firstAttribute="width" constant="62" id="58"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Password:" id="24">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<pathControl verticalHuggingPriority="750" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4">
<rect key="frame" x="87" y="83" width="206" height="26"/>
<rect key="frame" x="105" y="83" width="174" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<pathCell key="cell" selectable="YES" editable="YES" alignment="left" pathStyle="popUp" id="23">
<font key="font" metaFont="system"/>
@@ -51,7 +39,7 @@
</pathCell>
</pathControl>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5">
<rect key="frame" x="34" y="87" width="50" height="17"/>
<rect key="frame" x="52" y="87" width="50" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Keyfile:" id="22">
<font key="font" metaFont="system"/>
@@ -60,8 +48,11 @@
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6">
<rect key="frame" x="90" y="60" width="200" height="19"/>
<rect key="frame" x="108" y="60" width="168" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<constraints>
<constraint firstAttribute="width" constant="168" id="7T4-xj-PPw"/>
</constraints>
<buttonCell key="cell" type="roundRect" title="Generate Keyfile" bezelStyle="roundedRect" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="21">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="cellTitle"/>
@@ -71,7 +62,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="7">
<rect key="frame" x="298" y="143" width="31" height="25"/>
<rect key="frame" x="284" y="143" width="31" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<constraints>
<constraint firstAttribute="width" constant="31" id="59"/>
@@ -82,7 +73,7 @@
</buttonCell>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8">
<rect key="frame" x="298" y="84" width="31" height="25"/>
<rect key="frame" x="284" y="84" width="31" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSStopProgressTemplate" imagePosition="only" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="19">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -93,7 +84,7 @@
</connections>
</button>
<secureTextField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9" customClass="HNHRoundedSecureTextField">
<rect key="frame" x="90" y="145" width="200" height="22"/>
<rect key="frame" x="108" y="145" width="168" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="18">
<font key="font" metaFont="system"/>
@@ -105,7 +96,7 @@
</secureTextFieldCell>
</secureTextField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="10">
<rect key="frame" x="32" y="117" width="52" height="17"/>
<rect key="frame" x="50" y="117" width="52" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Repeat:" id="16">
<font key="font" metaFont="system"/>
@@ -114,7 +105,7 @@
</textFieldCell>
</textField>
<secureTextField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="11" customClass="HNHRoundedSecureTextField">
<rect key="frame" x="90" y="115" width="200" height="22"/>
<rect key="frame" x="108" y="115" width="168" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="15">
<font key="font" metaFont="system"/>
@@ -126,7 +117,7 @@
</secureTextFieldCell>
</secureTextField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="12">
<rect key="frame" x="123" y="175" width="135" height="17"/>
<rect key="frame" x="125" y="175" width="135" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<constraints>
<constraint firstAttribute="height" constant="17" id="13"/>
@@ -138,7 +129,7 @@
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="68">
<rect key="frame" x="185" y="13" width="150" height="32"/>
<rect key="frame" x="171" y="13" width="150" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Change Password" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="69">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -149,7 +140,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="72">
<rect key="frame" x="103" y="13" width="82" height="32"/>
<rect key="frame" x="89" y="13" width="82" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="73">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -162,17 +153,20 @@ Gw
<action selector="cancel:" target="-2" id="84"/>
</connections>
</button>
<button horizontalHuggingPriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="yKc-I9-uzv">
<rect key="frame" x="18" y="146" width="84" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Password:" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="OQz-DA-SoY">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
</subviews>
<constraints>
<constraint firstItem="4" firstAttribute="trailing" secondItem="6" secondAttribute="trailing" id="25"/>
<constraint firstItem="9" firstAttribute="top" secondItem="12" secondAttribute="bottom" constant="8" symbolic="YES" id="26"/>
<constraint firstItem="4" firstAttribute="leading" secondItem="5" secondAttribute="trailing" constant="8" symbolic="YES" id="27"/>
<constraint firstItem="4" firstAttribute="leading" secondItem="6" secondAttribute="leading" id="28"/>
<constraint firstItem="10" firstAttribute="baseline" secondItem="11" secondAttribute="baseline" id="29"/>
<constraint firstItem="7" firstAttribute="leading" secondItem="9" secondAttribute="trailing" constant="8" symbolic="YES" id="30"/>
<constraint firstItem="7" firstAttribute="leading" secondItem="8" secondAttribute="leading" id="31"/>
<constraint firstItem="4" firstAttribute="leading" secondItem="11" secondAttribute="leading" id="32"/>
<constraint firstItem="9" firstAttribute="leading" secondItem="11" secondAttribute="leading" id="33"/>
<constraint firstItem="4" firstAttribute="trailing" secondItem="11" secondAttribute="trailing" id="34"/>
<constraint firstItem="4" firstAttribute="top" secondItem="11" secondAttribute="bottom" constant="8" symbolic="YES" id="35"/>
<constraint firstItem="7" firstAttribute="top" secondItem="9" secondAttribute="top" id="36"/>
@@ -181,18 +175,27 @@ Gw
<constraint firstItem="12" firstAttribute="centerX" secondItem="9" secondAttribute="centerX" id="40"/>
<constraint firstItem="8" firstAttribute="centerY" secondItem="4" secondAttribute="centerY" id="41"/>
<constraint firstItem="4" firstAttribute="bottom" secondItem="5" secondAttribute="bottom" id="43"/>
<constraint firstItem="8" firstAttribute="leading" secondItem="4" secondAttribute="trailing" constant="8" symbolic="YES" id="46"/>
<constraint firstItem="3" firstAttribute="baseline" secondItem="9" secondAttribute="baseline" id="47"/>
<constraint firstItem="9" firstAttribute="leading" secondItem="3" secondAttribute="trailing" constant="8" symbolic="YES" id="48"/>
<constraint firstItem="12" firstAttribute="top" secondItem="2" secondAttribute="top" constant="20" symbolic="YES" id="53"/>
<constraint firstAttribute="trailing" secondItem="8" secondAttribute="trailing" constant="20" symbolic="YES" id="56"/>
<constraint firstAttribute="trailing" secondItem="7" secondAttribute="trailing" constant="20" symbolic="YES" id="57"/>
<constraint firstItem="3" firstAttribute="leading" secondItem="2" secondAttribute="leading" constant="20" symbolic="YES" id="60"/>
<constraint firstAttribute="trailing" secondItem="68" secondAttribute="trailing" constant="20" symbolic="YES" id="71"/>
<constraint firstItem="68" firstAttribute="leading" secondItem="72" secondAttribute="trailing" constant="12" symbolic="YES" id="75"/>
<constraint firstItem="72" firstAttribute="top" secondItem="6" secondAttribute="bottom" constant="20" symbolic="YES" id="76"/>
<constraint firstAttribute="bottom" secondItem="72" secondAttribute="bottom" constant="20" symbolic="YES" id="77"/>
<constraint firstAttribute="bottom" secondItem="68" secondAttribute="bottom" constant="20" symbolic="YES" id="78"/>
<constraint firstItem="6" firstAttribute="trailing" secondItem="4" secondAttribute="trailing" id="49e-nD-CHa"/>
<constraint firstItem="8" firstAttribute="leading" secondItem="4" secondAttribute="trailing" constant="8" id="7GY-2X-nJn"/>
<constraint firstItem="4" firstAttribute="leading" secondItem="5" secondAttribute="trailing" constant="8" id="7eR-m5-mhQ"/>
<constraint firstItem="9" firstAttribute="baseline" secondItem="yKc-I9-uzv" secondAttribute="baseline" id="DrZ-BA-xPv"/>
<constraint firstItem="7" firstAttribute="leading" secondItem="9" secondAttribute="trailing" constant="8" id="IqJ-u6-6jk"/>
<constraint firstItem="yKc-I9-uzv" firstAttribute="leading" secondItem="2" secondAttribute="leading" constant="20" symbolic="YES" id="OdM-OO-kNS"/>
<constraint firstItem="7" firstAttribute="leading" secondItem="9" secondAttribute="trailing" constant="8" symbolic="YES" id="PnG-bb-nYQ"/>
<constraint firstItem="yKc-I9-uzv" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="2" secondAttribute="leading" constant="20" symbolic="YES" id="R8d-VG-2we"/>
<constraint firstItem="9" firstAttribute="leading" secondItem="yKc-I9-uzv" secondAttribute="trailing" constant="8" symbolic="YES" id="f8B-Dm-rGD"/>
<constraint firstItem="6" firstAttribute="trailing" secondItem="9" secondAttribute="trailing" id="fQD-6S-tkb"/>
<constraint firstItem="6" firstAttribute="leading" secondItem="4" secondAttribute="leading" id="tie-Hu-X1C"/>
<constraint firstItem="6" firstAttribute="leading" secondItem="11" secondAttribute="leading" id="xV3-et-ECG"/>
<constraint firstItem="6" firstAttribute="leading" secondItem="9" secondAttribute="leading" id="zeJ-6i-fY3"/>
</constraints>
</view>
</window>