Created
November 15, 2015 02:19
-
-
Save takaheraw/59ef5f6826ede978fcc7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActivityLog { | |
func logActivity(activity: String) { | |
print("Log: \(activity)") | |
} | |
} | |
class FileCache { | |
func loadFiles(user: String) { | |
print("Load files for \(user)") | |
} | |
} | |
class AttackMonitor { | |
var monitorSuspiciousActivity: Bool = false { | |
didSet { | |
print("Monitoring for attack: \(monitorSuspiciousActivity)") | |
} | |
} | |
} | |
class AuthenticationManager { | |
private let log = ActivityLog() | |
private let cache = FileCache() | |
private let monitor = AttackMonitor() | |
func authenticate(user: String, pass: String) -> Bool { | |
var result = false | |
if (user == "bob" && pass == "secret") { | |
result = true | |
print("User \(user) is authenticated") | |
log.logActivity("Authenticated \(user)") | |
cache.loadFiles(user) | |
monitor.monitorSuspiciousActivity = false | |
} else { | |
print("Faild authentication attempt") | |
log.logActivity("Failed authentication: \(user)") | |
monitor.monitorSuspiciousActivity = true | |
} | |
return result | |
} | |
} | |
let authM = AuthenticationManager() | |
authM.authenticate("bob", pass: "secret") | |
print("--------") | |
authM.authenticate("joe", pass: "shhh") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment