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.
See also
-
A value that matches a
URLwith apasswordproperty ofnil.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 usePassword("")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) //> trueDeclaration
Swift
public static let missing: URLMatchable -
Wraps the given string to create a new
Passwordvalue. It matchesURLs based on theirpasswordproperty.See also
Declaration
Swift
public init(_ password: String)Parameters
passwordThe password to match. It will be compared for equality against
URL’spasswordproperty. -
Predicate that determines whether a
Passwordmatches a givenURL.Declaration
Swift
public func matches(url: URL) -> BoolParameters
urlThe
URLto be matched.Return Value
trueif the wrapped password is equivalent tourl.password. Otherwise,false.
View on GitHub
Install in Dash
Password Structure Reference