generate random password
This commit is contained in:
parent
95680138a4
commit
9f3b13f8b0
3 changed files with 18 additions and 1 deletions
|
|
@ -34,6 +34,22 @@ class Utils {
|
||||||
}
|
}
|
||||||
return lastUpdatedTimeString
|
return lastUpdatedTimeString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static func randomString(length: Int) -> String {
|
||||||
|
|
||||||
|
let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||||
|
let len = UInt32(letters.length)
|
||||||
|
|
||||||
|
var randomString = ""
|
||||||
|
|
||||||
|
for _ in 0 ..< length {
|
||||||
|
let rand = arc4random_uniform(len)
|
||||||
|
var nextChar = letters.character(at: Int(rand))
|
||||||
|
randomString += NSString(characters: &nextChar, length: 1) as String
|
||||||
|
}
|
||||||
|
|
||||||
|
return randomString
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://gist.github.com/NikolaiRuhe/eeb135d20c84a7097516
|
// https://gist.github.com/NikolaiRuhe/eeb135d20c84a7097516
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ class Password {
|
||||||
private func getAdditionValue(withKey key: String) -> String? {
|
private func getAdditionValue(withKey key: String) -> String? {
|
||||||
return self.additions[key]
|
return self.additions[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension PasswordEntity {
|
extension PasswordEntity {
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,6 @@ class FillPasswordTableViewCell: UITableViewCell {
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func generatePassword(_ sender: UIButton) {
|
@IBAction func generatePassword(_ sender: UIButton) {
|
||||||
contentTextField.text = "4-r4d0m-p455w0rd"
|
contentTextField.text = Utils.randomString(length: 16)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue