diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2019-05-21 19:40:16 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2019-05-22 11:35:38 +0200 |
| commit | 2b3239e68a38be6048a7ff68b215a414653fbb3e (patch) | |
| tree | a70cd4468c0887aa6e8a9b51200b2529475646b8 | |
| parent | 860dbebbfe49226508765dc04072104971fa41a2 (diff) | |
| download | mullvadvpn-2b3239e68a38be6048a7ff68b215a414653fbb3e.tar.xz mullvadvpn-2b3239e68a38be6048a7ff68b215a414653fbb3e.zip | |
Add account input validation
| -rw-r--r-- | ios/MullvadVPN/Base.lproj/Main.storyboard | 3 | ||||
| -rw-r--r-- | ios/MullvadVPN/LoginViewController.swift | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/ios/MullvadVPN/Base.lproj/Main.storyboard b/ios/MullvadVPN/Base.lproj/Main.storyboard index 6646fe40c1..6a732e005c 100644 --- a/ios/MullvadVPN/Base.lproj/Main.storyboard +++ b/ios/MullvadVPN/Base.lproj/Main.storyboard @@ -64,6 +64,9 @@ <nil key="textColor"/> <fontDescription key="fontDescription" type="system" pointSize="20"/> <textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="numberPad" enablesReturnKeyAutomatically="YES" smartDashesType="no" smartInsertDeleteType="no" smartQuotesType="no" textContentType="username"/> + <connections> + <outlet property="delegate" destination="BYZ-38-t0r" id="jeF-vG-YXi"/> + </connections> </textField> </subviews> <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> diff --git a/ios/MullvadVPN/LoginViewController.swift b/ios/MullvadVPN/LoginViewController.swift index 0fad658a44..6bac14f878 100644 --- a/ios/MullvadVPN/LoginViewController.swift +++ b/ios/MullvadVPN/LoginViewController.swift @@ -11,8 +11,9 @@ import ProcedureKit import os.log private let kMinimumAccountTokenLength = 10 +private let kValidAccountTokenCharacterSet = CharacterSet(charactersIn: "01234567890") -class LoginViewController: UIViewController, HeaderBarViewControllerDelegate { +class LoginViewController: UIViewController, HeaderBarViewControllerDelegate, UITextFieldDelegate { @IBOutlet var keyboardToolbar: UIToolbar! @IBOutlet var keyboardToolbarLoginButton: UIBarButtonItem! @@ -129,6 +130,13 @@ class LoginViewController: UIViewController, HeaderBarViewControllerDelegate { updateKeyboardToolbar() } + // MARK: - UITextFieldDelegate + + func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + // prevent the change if the replacement string contains disallowed characters + return string.unicodeScalars.allSatisfy { kValidAccountTokenCharacterSet.contains($0) } + } + // MARK: - IBActions @IBAction func cancelLogin() { |
