Skip to content

Instantly share code, notes, and snippets.

@takaheraw
Created November 15, 2015 02:19
Show Gist options
  • Save takaheraw/59ef5f6826ede978fcc7 to your computer and use it in GitHub Desktop.
Save takaheraw/59ef5f6826ede978fcc7 to your computer and use it in GitHub Desktop.
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