SPB Git

Repository Public MIT

GlassSecureFieldExample.swift 3.0 KB 81 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Examples/Gallery/Forms/GlassSecureFieldExample.swift8// Module           : Examples9// Repository       : https://git.spboucher.ai/sp-glasskit10// Project Website  : https://glass.spboucher.ai11// Created          : 2026-12-0212// Last Modified    : 2026-12-0213//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import SPGlassKit4344public struct GlassSecureFieldExample: GlassExample {45    public static let componentID = "glass-secure-field"46    @State private var current = ""47    @State private var new = ""48    @State private var pin = ""4950    public init() {}5152    public var body: some View {53        ScrollView {54            VStack(alignment: .leading, spacing: 20) {55                GlassSecureField("Current password", text: $current, validation: GlassFieldValidation(.required()))5657                GlassSecureField(58                    "New password",59                    text: $new,60                    prompt: "At least 12 characters",61                    helper: "Use a phrase you can remember.",62                    content: .newPassword,63                    allowsReveal: true,64                    validation: GlassFieldValidation(.required(), .minLength(12)),65                    validateOn: .always66                )6768                GlassSecureField("Device PIN", text: $pin, allowsReveal: true, errorMessage: pin.isEmpty ? nil : "Demo: this PIN is always rejected.")6970                // Only the length is ever displayed: the example never prints the secret.71                Text("New password length: \(new.count)")72                    .font(.callout)73                    .foregroundStyle(.secondary)74            }75            .padding()76        }77    }78}7980#Preview("GlassSecureField") { GlassSecureFieldExample() }81
Files main
Menu

Theme