SP GlassKit1.1.0

GlassSecureField

Secure field with optional explicit reveal; its content is never logged.

  • Content
  • iOS 26 · iPadOS 26 · macOS 26
  • Version 1.1.0
  • glass-secure-field

Content on an opaque, readable surface. Glass is kept for controls.

GlassSecureField running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-secure-field

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-secure-field
ModuleSPGlassForms
Kindcontent-component — the system SecureField on an opaque themed surface
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Forms/GlassSecureFieldExample.swift

Minimal usage

Swift
@State private var password = ""

GlassSecureField("Password", text: $password)

Variants

VariantUse
content: .passwordAn existing password; password managers offer to fill it.
content: .newPasswordA password being chosen; the system may suggest a strong one.
allowsReveal: trueAdds a button that shows the content in clear. Off by default.
validation: / validateOn: / errorMessage:Same rules as GlassTextField.

Parameters

ParameterTypeDefaultMeaning
labelLocalizedStringKey—Label above the field; also its accessibility label.
textBinding<String>—The secret.
promptLocalizedStringKey?nilPlaceholder.
helperLocalizedStringKey?nilHelper text.
systemImageString?nilLeading SF Symbol ("lock"), decorative (1.1).
contentGlassSecureContent.passwordContent type for AutoFill.
allowsRevealBoolfalseShows the reveal button.
validationGlassFieldValidation.noneRules of the field.
validateOnGlassValidationTrigger.afterEditingWhen the message starts to show.
errorMessageString?nilExternal error.

States

Hidden (default, a SecureField), revealed (a TextField with autocorrection off and the password content type), focused, error, disabled. A disabled field is never shown in clear. The revealed state is local, starts hidden every time the field is created and is not stored anywhere.

Advanced example

Swift
GlassSecureField(
    "New password", text: $password,
    helper: "At least 12 characters.",
    content: .newPassword,
    allowsReveal: true,
    validation: GlassFieldValidation(.required(), .minLength(12)),
    errorMessage: model.passwordError
)
.onSubmit { model.changePassword(to: password) }

Accessibility

  • The reveal button is labelled with the action it performs: "Show password", then "Hide password" (localised).
  • The button has the platform's minimum hit target and is reachable with the keyboard.
  • Errors are an icon and a sentence, not colour alone.
  • The field is marked privacySensitive(), so the system can redact it where it redacts private content.

Limits

  • The component never logs, stores or copies the content; what the host does with the binding is its own responsibility.
  • Revealing swaps the secure field for a plain one; the focus is handed over in code, but the caret position is not kept.
  • GlassKit cannot prevent screen recording or screenshots.
  • AutoFill, strong password suggestions and the focus hand-over were not exercised on a running device here.

Example

Complete example (compiled with the package)
import SwiftUI
import SPGlassKit

public struct GlassSecureFieldExample: GlassExample {
    public static let componentID = "glass-secure-field"
    @State private var current = ""
    @State private var new = ""
    @State private var pin = ""

    public init() {}

    public var body: some View {
        ScrollView {
            VStack(alignment: .leading, spacing: 20) {
                GlassSecureField("Current password", text: $current, validation: GlassFieldValidation(.required()))

                GlassSecureField(
                    "New password",
                    text: $new,
                    prompt: "At least 12 characters",
                    helper: "Use a phrase you can remember.",
                    content: .newPassword,
                    allowsReveal: true,
                    validation: GlassFieldValidation(.required(), .minLength(12)),
                    validateOn: .always
                )

                GlassSecureField("Device PIN", text: $pin, allowsReveal: true, errorMessage: pin.isEmpty ? nil : "Demo: this PIN is always rejected.")

                // Only the length is ever displayed: the example never prints the secret.
                Text("New password length: \(new.count)")
                    .font(.callout)
                    .foregroundStyle(.secondary)
            }
            .padding()
        }
    }
}

#Preview("GlassSecureField") { GlassSecureFieldExample() }

Registry entry

Identifierglass-secure-field
Version1.1.0
Depends onglass-forms-support, glass-foundation
FrameworksSwiftUI
Public symbolsGlassSecureContent, GlassSecureFieldReveal, GlassSecureField
LicenceMIT
Manifestmanifest.json

Files