Password

public struct Password : URLMatchable

Type that matches a URL based on comparison with the URL’s password propery.

Usage:

let url = URL(string: "https://user:pass@example.com")!
Password("pass").matches(url) //> true

Note

RFC 1738 makes a distinction between empty ("") passwords and no (nil) passwords. In the uncommon case you need to match a URL with an empty password (i.e.http://foo:@example.com”), create a Password with an empty string: Password(""). The much more common no password can be matched with Password.missing.

  • A value that matches a URL with a password property of nil.

    RFC 1738 (and this package) makes a distinction between empty ("") passwords and no (nil) passwords:

    Note that an empty user name or password is different than no user name or password.

    As such, this value only matches against no (nil) passwords. In practice this is a pretty meaningless distinction because please-god-don’t-put-auth-info-in-your-URLs. But if there is occation to match an empty password, one can use Password("") to achieve that purpose.

    Usage:

    let password = URL(string: "http://user:pass@example.com")!
    let emptyPassword = URL(string: "http://user:@example.com")!
    let noPassword = URL(string: "http://example.com")!
    Password.missing.matches(url: password)      //> false
    Password.missing.matches(url: emptyPassword) //> false
    Password.missing.matches(url: noPassword)    //> true
    

    Declaration

    Swift

    public static let missing: URLMatchable
  • Wraps the given string to create a new Password value. It matches URLs based on their password property.

    See also

    User

    Declaration

    Swift

    public init(_ password: String)

    Parameters

    password

    The password to match. It will be compared for equality against URL’s password property.

  • Predicate that determines whether a Password matches a given URL.

    Declaration

    Swift

    public func matches(url: URL) -> Bool

    Parameters

    url

    The URL to be matched.

    Return Value

    true if the wrapped password is equivalent to url.password. Otherwise, false.