Password creator view not allows toggling for entry/global defaults (UI only)

This commit is contained in:
michael starke
2014-10-21 16:49:37 +02:00
parent a8a4ee4d53
commit c2def5653e
3 changed files with 60 additions and 40 deletions

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="13F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment defaultVersion="1080" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPPasswordCreatorViewController">
@@ -27,14 +27,13 @@
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="1">
<rect key="frame" x="0.0" y="0.0" width="346" height="275"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="148">
<rect key="frame" x="18" y="237" width="66" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Password:" id="149">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -43,7 +42,6 @@
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="152">
<rect key="frame" x="90" y="231" width="200" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="200" id="621"/>
</constraints>
@@ -55,12 +53,10 @@
</textField>
<slider verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="173">
<rect key="frame" x="88" y="204" width="204" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<sliderCell key="cell" state="on" alignment="left" maxValue="100" doubleValue="50" tickMarkPosition="above" sliderType="linear" id="174"/>
</slider>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="178">
<rect key="frame" x="18" y="206" width="66" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Length:" id="179">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -69,7 +65,6 @@
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="182">
<rect key="frame" x="298" y="203" width="28" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="28" id="eVc-Kg-bCi"/>
</constraints>
@@ -81,14 +76,12 @@
</textField>
<box autoresizesSubviews="NO" title="Allowed Characters" borderType="line" translatesAutoresizingMaskIntoConstraints="NO" id="332">
<rect key="frame" x="17" y="72" width="312" height="94"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView">
<rect key="frame" x="1" y="1" width="310" height="78"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="411">
<rect key="frame" x="18" y="19" width="274" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="412" customClass="HNHRoundedTextFieldCell">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
@@ -97,7 +90,6 @@
</textField>
<button verticalHuggingPriority="750" tag="1" translatesAutoresizingMaskIntoConstraints="NO" id="452">
<rect key="frame" x="18" y="49" width="37" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundRect" title="A-Z" bezelStyle="roundedRect" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="453">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="cellTitle"/>
@@ -108,7 +100,6 @@
</button>
<button verticalHuggingPriority="750" tag="2" translatesAutoresizingMaskIntoConstraints="NO" id="456">
<rect key="frame" x="63" y="49" width="35" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundRect" title="a-z" bezelStyle="roundedRect" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="457">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="cellTitle"/>
@@ -119,7 +110,6 @@
</button>
<button verticalHuggingPriority="750" tag="4" translatesAutoresizingMaskIntoConstraints="NO" id="460">
<rect key="frame" x="106" y="49" width="37" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundRect" title="0-9" bezelStyle="roundedRect" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="461">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="cellTitle"/>
@@ -130,7 +120,6 @@
</button>
<button verticalHuggingPriority="750" tag="8" translatesAutoresizingMaskIntoConstraints="NO" id="464">
<rect key="frame" x="151" y="49" width="31" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundRect" title="#!?" bezelStyle="roundedRect" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="465">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="cellTitle"/>
@@ -141,7 +130,6 @@
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="468">
<rect key="frame" x="190" y="49" width="59" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundRect" title="Custom" bezelStyle="roundedRect" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="469">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="cellTitle"/>
@@ -171,7 +159,6 @@
</box>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="494">
<rect key="frame" x="227" y="18" width="99" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundTextured" title="Use Password" bezelStyle="texturedRounded" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="495">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -182,7 +169,6 @@
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="500">
<rect key="frame" x="18" y="52" width="209" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Copy password to pasteboard" bezelStyle="regularSquare" imagePosition="left" inset="2" id="501">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@@ -190,7 +176,6 @@
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="509">
<rect key="frame" x="298" y="231" width="28" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSRefreshTemplate" imagePosition="only" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="510">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -201,7 +186,6 @@
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="613">
<rect key="frame" x="163" y="18" width="56" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundTextured" title="Cancel" bezelStyle="texturedRounded" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="614">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -212,12 +196,10 @@
</button>
<levelIndicator verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="635">
<rect key="frame" x="90" y="174" width="165" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<levelIndicatorCell key="cell" alignment="left" doubleValue="10" maxValue="90" warningValue="55" criticalValue="30" levelIndicatorStyle="continuousCapacity" id="636" customClass="HNHLevelIndicatorCell"/>
</levelIndicator>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="646">
<rect key="frame" x="18" y="174" width="66" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Entropy:" id="647">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -226,7 +208,6 @@
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="652">
<rect key="frame" x="261" y="174" width="67" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="25000 bit" id="653">
<numberFormatter key="formatter" formatterBehavior="custom10_4" positiveFormat="# bit" negativeFormat="# bit" usesGroupingSeparator="NO" paddingCharacter="*" groupingSize="0" minimumIntegerDigits="0" maximumIntegerDigits="309" decimalSeparator="," groupingSeparator="." currencyDecimalSeparator="," plusSign="+" minusSign="-" notANumberSymbol="NaN" perMillSymbol="‰" percentSymbol="%" exponentSymbol="E" positivePrefix="" positiveSuffix=" bit" negativePrefix="-" negativeSuffix=" bit" id="681"/>
<font key="font" metaFont="system"/>
@@ -234,9 +215,8 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="yil-UB-jtO">
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="yil-UB-jtO">
<rect key="frame" x="20" y="18" width="83" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundTextured" title="Set Default" bezelStyle="texturedRounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Wvs-Md-Ob8">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -279,9 +259,12 @@
<constraint firstAttribute="trailing" secondItem="652" secondAttribute="trailing" constant="20" symbolic="YES" id="679"/>
<constraint firstItem="635" firstAttribute="leading" secondItem="152" secondAttribute="leading" id="680"/>
<constraint firstItem="613" firstAttribute="top" secondItem="500" secondAttribute="bottom" constant="12" id="684"/>
<constraint firstItem="613" firstAttribute="leading" secondItem="yil-UB-jtO" secondAttribute="trailing" constant="60" id="59d-1n-jSa"/>
<constraint firstItem="646" firstAttribute="trailing" secondItem="178" secondAttribute="trailing" id="6kR-jk-E8r"/>
<constraint firstItem="yil-UB-jtO" firstAttribute="leading" secondItem="500" secondAttribute="leading" id="Hic-qB-mt4"/>
<constraint firstItem="148" firstAttribute="trailing" secondItem="178" secondAttribute="trailing" id="KpM-xy-ZTB"/>
<constraint firstItem="509" firstAttribute="leading" secondItem="182" secondAttribute="leading" id="QZ5-Ge-aq8"/>
<constraint firstAttribute="bottom" secondItem="yil-UB-jtO" secondAttribute="bottom" constant="20" id="eYK-Hw-fyy"/>
<constraint firstItem="646" firstAttribute="leading" secondItem="1" secondAttribute="leading" constant="20" symbolic="YES" id="jPa-QR-GAy"/>
<constraint firstItem="178" firstAttribute="leading" secondItem="1" secondAttribute="leading" constant="20" symbolic="YES" id="pAc-di-F68"/>
</constraints>

View File

@@ -12,6 +12,7 @@
@property (copy, readonly) NSString *generatedPassword;
@property (weak) id closeTarget;
@property (assign) BOOL allowsEntryDefaults;
/**
* Should be called to reset the generator

View File

@@ -12,14 +12,6 @@
#import "MPUniqueCharactersFormatter.h"
#import "MPSettingsHelper.h"
typedef NS_ENUM(NSUInteger, MPPasswordRating) {
MPPasswordTerrible = 10,
MPPasswordWeak = 20,
MPPasswordOk = 30,
MPPasswordGood = 50,
MPPasswordStrong = 60
};
/*
0 - 20 Terrible
@@ -30,11 +22,25 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
Skale 0-90
*/
typedef NS_ENUM(NSUInteger, MPPasswordRating) {
MPPasswordTerrible = 10,
MPPasswordWeak = 20,
MPPasswordOk = 30,
MPPasswordGood = 50,
MPPasswordStrong = 60
};
typedef NS_ENUM(NSUInteger, MPDefaultDomain) {
MPEntryDomain,
MPGlobalDomain,
};
#define MIN_PASSWORD_LENGTH 1
#define MAX_PASSWORD_LENGTH 256
@interface MPPasswordCreatorViewController () {
MPPasswordCharacterFlags _characterFlags;
MPDefaultDomain _defaultDomain;
}
@property (nonatomic, copy) NSString *password;
@property (copy) NSString *generatedPassword;
@@ -75,13 +81,15 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
_useCustomString = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyPasswordUseCustomString];
_customString = [[NSUserDefaults standardUserDefaults] stringForKey:kMPSettingsKeyPasswordCustomString];
_entropy = 0.0;
_defaultDomain = MPGlobalDomain;
_allowsEntryDefaults = NO;
}
return self;
}
- (void)awakeFromNib {
[self.setDefaultButton setEnabled:NO];
[self.passwordLengthSlider setMinValue:MIN_PASSWORD_LENGTH];
[self.passwordLengthSlider setMaxValue:MAX_PASSWORD_LENGTH];
[self.passwordLengthSlider setContinuous:YES];
@@ -93,15 +101,15 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
id formatter = [[MPUniqueCharactersFormatter alloc] init];
[self. customCharactersTextField setFormatter:formatter];
[self.passwordLengthSlider bind:NSValueBinding toObject:self withKeyPath:@"passwordLength" options:nil];
[self.passwordLengthTextField bind:NSValueBinding toObject:self withKeyPath:@"passwordLength" options:nil];
[self.passwordTextField bind:NSValueBinding toObject:self withKeyPath:@"password" options:nil];
[self.passwordLengthSlider bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(passwordLength)) options:nil];
[self.passwordLengthTextField bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(passwordLength)) options:nil];
[self.passwordTextField bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(password)) options:nil];
[self.entropyIndicator bind:NSValueBinding toObject:self withKeyPath:@"entropy" options:nil];
[self.entropyTextField bind:NSValueBinding toObject:self withKeyPath:@"entropy" options:nil];
[self.entropyIndicator bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(entropy)) options:nil];
[self.entropyTextField bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(entropy)) options:nil];
[self.customCharactersTextField setDelegate:self];
[self.customButton bind:NSValueBinding toObject:self withKeyPath:@"useCustomString" options:nil];
[self.customButton bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(useCustomString)) options:nil];
NSString *copyToPasteBoardKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyCopyGeneratedPasswordToClipboard];
NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController];
@@ -112,6 +120,8 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
[self.lowerCaseButton setTag:MPPasswordCharactersLowerCase];
[self.symbolsButton setTag:MPPasswordCharactersSymbols];
[self updateResponderChain];
[self _updateSetDefaultButton];
[self reset];
}
@@ -120,6 +130,18 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
[self _generatePassword:self];
}
#pragma mark -
#pragma mark Events
- (void)flagsChanged:(NSEvent *)theEvent {
if(!self.allowsEntryDefaults) {
return;
}
BOOL altIsDown = (0 != ([NSEvent modifierFlags] & NSAlternateKeyMask));
_defaultDomain = altIsDown ? MPEntryDomain : MPGlobalDomain;
[self _updateSetDefaultButton];
}
#pragma mark -
#pragma mark Actions
@@ -203,6 +225,20 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
#pragma mark -
#pragma mark Helper
- (void)_updateSetDefaultButton {
switch (_defaultDomain) {
case MPEntryDomain:
[self.setDefaultButton setTitle:NSLocalizedString(@"SET_DEFAULT_ENTRY_PASSWORD_RULE", "")];
break;
case MPGlobalDomain:
default:
[self.setDefaultButton setTitle:NSLocalizedString(@"SET_DEFAULT_GENERAL_PASSWORD_RULE", "")];
break;
}
}
- (void)_resetCharacters {
if(_useCustomString) {
[_customButton setState:NSOnState];