Created
October 30, 2021 22:26
-
-
Save JohannMG/31d4612f1922fda27edfe7c295decaef to your computer and use it in GitHub Desktop.
Made this view in UIKit before and remade in SwiftUI. Lets you create a set of parameters to show to the user to visually identify if they have a password that will pass requirements.
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
// | |
// PasswordRequirementsView.swift | |
// SwiftUiPlayground | |
// | |
// Created by Johann Garces on 10/30/21. | |
// | |
/* | |
* Made this view in UIKit before and remade in SwiftUI. | |
* Lets you create a set of parameters to show to the user to visually identify | |
* if they have a password that will pass requirements. | |
*/ | |
import SwiftUI | |
struct PasswordRequirementsView: View { | |
var password: String | |
var body: some View { | |
VStack(alignment: .leading, spacing: 4.0) { | |
Text("Password must contain:") | |
PasswordRequirementTextView(password: password, | |
userMessage: "• More than 8 characters", | |
passwordRequirement: {$0.count >= 8}) | |
PasswordRequirementTextView(password: password, | |
userMessage: "• Fewer than 100 characters", | |
passwordRequirement: {$0.count < 100}) | |
// Add more requirements here | |
} | |
} | |
} | |
struct PasswordRequirementTextView: View { | |
typealias StringVerification = (String) -> Bool | |
var password: String | |
var userMessage: String | |
var passwordRequirement: StringVerification | |
var body: some View { | |
HStack{ | |
Text(userMessage) | |
.foregroundColor( passwordRequirement(password) ? .green : .black) | |
Spacer() | |
} | |
} | |
} | |
struct PasswordRequirementsView_Previews: PreviewProvider { | |
static var previews: some View { | |
PasswordRequirementsView(password: "SOMEsomething") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment