Skip to content

Commit

Permalink
added verification and refactored dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Jun 4, 2022
1 parent 62cb8bb commit d38bc48
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 105 deletions.
2 changes: 2 additions & 0 deletions XCreds/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import Cocoa
@main
class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet weak var loginPasswordWindow: NSWindow!
@IBOutlet var window: NSWindow!
var mainController:MainController?

func applicationDidFinishLaunching(_ aNotification: Notification) {
mainMenu.statusBarItem.menu = mainMenu.mainMenu


mainController = MainController.init()
mainController?.run()
}
Expand Down
2 changes: 1 addition & 1 deletion XCreds/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="xCreds" customModuleProvider="target"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="XCreds" customModuleProvider="target"/>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
<items>
Expand Down
34 changes: 34 additions & 0 deletions XCreds/LoginPasswordWindowController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// LoginPasswordWindowController.swift
// XCreds
//
// Created by Timothy Perfitt on 6/4/22.
//

import Cocoa

class LoginPasswordWindowController: NSWindowController {

@IBOutlet weak var passwordTextField: NSSecureTextField!

var password:String?
override func windowDidLoad() {
super.windowDidLoad()

// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}

@IBAction func updateButtonPressed(_ sender: Any) {
if self.window?.isModalPanel==true {
password=passwordTextField.stringValue
NSApp.stopModal(withCode: .OK)

}
}
@IBAction func cancelButtonPressed(_ sender: Any) {
if self.window?.isModalPanel==true {
NSApp.stopModal(withCode: .cancel)
self.window?.close()
}
}
}
113 changes: 113 additions & 0 deletions XCreds/LoginPasswordWindowController.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="LoginPasswordWindowController" customModule="XCreds" customModuleProvider="target">
<connections>
<outlet property="passwordTextField" destination="uxk-Kc-Ey2" id="NeY-1n-1d3"/>
<outlet property="window" destination="y1s-aj-r0T" id="ZcP-JQ-mk1"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" frameAutosaveName="" animationBehavior="default" titlebarAppearsTransparent="YES" titleVisibility="hidden" id="y1s-aj-r0T">
<windowStyleMask key="styleMask" titled="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="530" y="324" width="497" height="189"/>
<rect key="screenRect" x="0.0" y="0.0" width="1536" height="935"/>
<view key="contentView" id="keP-aO-VT7">
<rect key="frame" x="0.0" y="0.0" width="497" height="189"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GHv-Is-FVt">
<rect key="frame" x="20" y="121" width="68" height="68"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="NSApplicationIcon" id="i1e-r0-Waa"/>
</imageView>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NQJ-DJ-Vk6">
<rect key="frame" x="94" y="118" width="385" height="64"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" selectable="YES" id="Kf4-Rd-r7U">
<font key="font" metaFont="systemBold"/>
<string key="title">Please enter your login password. XCreds saves the login password to the keychain to sync your login password and keychain password with your cloud password.</string>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="or1-FG-c7l">
<rect key="frame" x="96" y="108" width="215" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="To allow this, enter your login password." id="NBo-xg-6iv">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Vgp-AS-5WP">
<rect key="frame" x="96" y="76" width="66" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Password:" id="gjN-RB-inR">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<secureTextField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uxk-Kc-Ey2">
<rect key="frame" x="168" y="73" width="309" height="21"/>
<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="C9u-SH-tmE">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<allowedInputSourceLocales>
<string>NSAllRomanInputSourcesLocaleIdentifier</string>
</allowedInputSourceLocales>
</secureTextFieldCell>
</secureTextField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gTn-ws-NVT">
<rect key="frame" x="405" y="13" width="79" height="32"/>
<buttonCell key="cell" type="push" title="Update" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Koa-hU-IdG">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
</buttonCell>
<connections>
<action selector="updateButtonPressed:" target="-2" id="0Yw-3m-Zc7"/>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="0Wv-NR-a6r">
<rect key="frame" x="330" y="13" width="76" height="32"/>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="yk2-3t-h59">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
Gw
</string>
</buttonCell>
<connections>
<action selector="cancelButtonPressed:" target="-2" id="qAB-hi-1zy"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="gTn-ws-NVT" secondAttribute="bottom" constant="20" symbolic="YES" id="1PF-dv-8LN"/>
<constraint firstAttribute="trailing" secondItem="gTn-ws-NVT" secondAttribute="trailing" constant="20" symbolic="YES" id="Ca3-N3-wr2"/>
<constraint firstItem="gTn-ws-NVT" firstAttribute="leading" secondItem="0Wv-NR-a6r" secondAttribute="trailing" constant="13" id="cuy-Mu-Sgh"/>
<constraint firstItem="0Wv-NR-a6r" firstAttribute="centerY" secondItem="gTn-ws-NVT" secondAttribute="centerY" id="plG-CO-NAT"/>
</constraints>
</view>
<connections>
<outlet property="delegate" destination="-2" id="WxA-Qo-qaN"/>
</connections>
<point key="canvasLocation" x="122.5" y="341.5"/>
</window>
</objects>
<resources>
<image name="NSApplicationIcon" width="32" height="32"/>
</resources>
</document>
64 changes: 43 additions & 21 deletions XCreds/MainController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,34 @@ class MainController: NSObject {
//now we set the password.

DispatchQueue.main.async {
if let userInfo = notification.userInfo, let newPassword = userInfo["password"] as? String {
let password = self.localPassword()
if let userInfo = notification.userInfo, let cloudPassword = userInfo["password"] as? String {
let localPassword = self.localPassword()

if let localPassword = localPassword {
let verifyOIDPassword = VerifyOIDCPassword.init(windowNibName: NSNib.Name("VerifyOIDCPassword"))
NSApp.activate(ignoringOtherApps: true)

while true {
let response = NSApp.runModal(for: verifyOIDPassword.window!)
if response == .cancel {
verifyOIDPassword.window?.close()
break
}
let verifyCloudPassword = verifyOIDPassword.password

if verifyCloudPassword == cloudPassword {
try? PasswordUtils.changeLocalUserAndKeychainPassword(localPassword, newPassword1: cloudPassword, newPassword2: cloudPassword)
verifyOIDPassword.window?.close()
break;

}
else {
verifyOIDPassword.window?.shake(self)
}

}


if let password = password {
try? PasswordUtils.changeLocalUserAndKeychainPassword(password, newPassword1: newPassword, newPassword2: newPassword)
}

ScheduleManager.shared.startCredentialCheck()
Expand All @@ -43,32 +66,31 @@ class MainController: NSObject {
return password
}
}
while (true){
let passwordWindowController = LoginPasswordWindowController.init(windowNibName: NSNib.Name("LoginPasswordWindowController"))

let alertController = NSAlert()

alertController.messageText = "Please enter your local password"
alertController.addButton(withTitle: "OK")
alertController.addButton(withTitle: "Cancel")

let localPassword = NSSecureTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 24))

alertController.accessoryView = localPassword
localPassword.becomeFirstResponder()

let response = alertController.runModal()

while (true){
NSApp.activate(ignoringOtherApps: true)
let response = NSApp.runModal(for: passwordWindowController.window!)

if response == .alertSecondButtonReturn {
if response == .cancel {
break
}
let isPasswordValid = PasswordUtils.verifyCurrentUserPassword(password: localPassword.stringValue)
let localPassword = passwordWindowController.password
guard let localPassword = localPassword else {
continue
}
let isPasswordValid = PasswordUtils.verifyCurrentUserPassword(password:localPassword )
if isPasswordValid==true {
let err = keychainUtil.setPassword("xcreds", pass: localPassword.stringValue)
passwordWindowController.window?.close()
let err = keychainUtil.setPassword("xcreds", pass: localPassword)
if err != OSStatus(errSecSuccess) {
return nil
}
return localPassword.stringValue
return localPassword
}
else{
passwordWindowController.window?.shake(self)
}
}

Expand Down
2 changes: 1 addition & 1 deletion XCreds/WebView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="WebViewController" customModule="xCreds" customModuleProvider="target">
<customObject id="-2" userLabel="File's Owner" customClass="WebViewController" customModule="XCreds" customModuleProvider="target">
<connections>
<outlet property="cancelButton" destination="k1y-g2-hDK" id="OP0-sn-o5u"/>
<outlet property="webView" destination="p1x-1L-05D" id="hJN-Xq-dh8"/>
Expand Down
36 changes: 36 additions & 0 deletions XCreds/Window+Shake.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Window+Shake.swift
// XCreds
//
// Created by Timothy Perfitt on 6/4/22.
//

import Foundation
import Cocoa

extension NSWindow {
@objc func shake(_ sender: AnyObject?) {
let numberOfShakes = 3
let durationOfShake = 0.4
let vigourOfShake : CGFloat = 0.03
let frame : CGRect = (self.frame)
let shakeAnimation :CAKeyframeAnimation = CAKeyframeAnimation()

let shakePath = CGMutablePath()
shakePath.move( to: CGPoint(x:NSMinX(frame), y:NSMinY(frame)))

for _ in 0...numberOfShakes-1 {
shakePath.addLine(to: CGPoint(x:NSMinX(frame) - frame.size.width * vigourOfShake, y:NSMinY(frame)))
shakePath.addLine(to: CGPoint(x:NSMinX(frame) + frame.size.width * vigourOfShake, y:NSMinY(frame)))
}

shakePath.closeSubpath()
shakeAnimation.path = shakePath
shakeAnimation.duration = durationOfShake

let animations = [NSAnimatablePropertyKey( "frameOrigin") : shakeAnimation]

self.animations = animations
self.animator().setFrameOrigin(NSPoint(x: frame.minX, y: frame.minY))
}
}
Loading

0 comments on commit d38bc48

Please sign in to comment.