 }
 
 public extension Generator {
+    /**
+    Calculates the current password based on the generator's configuration. The password generated
+    will be constant for a counter-based generator, but for a timer-based generator the password
+    will depend on the current time when this method is called.
+
+    Note: Calling this method does *not* increment the counter of a counter-based generator.
+
+    :returns: The current password, or `nil` if a password could not be generated.
+    */
     var password: String? {
         if !validateGenerator(factor, secret, algorithm, digits) { return nil }
         let counter = counterForGeneratorWithFactor(self.factor, atTimeIntervalSince1970: NSDate().timeIntervalSince1970)

        self.digits = digits
    }

    public enum Factor: Equatable {
        case Counter(UInt64)
        case Timer(period: NSTimeInterval)
    }

    public enum Algorithm: Equatable {
        case SHA1, SHA256, SHA512
    }


import Foundation

/// A `Generator` contains all of the parameters needed to generate a one-time password.
public struct Generator: Equatable {

    /// The moving factor, either timer- or counter-based.
    public let factor: Factor

    /// The secret shared between the client and server.
    public let secret: NSData

    /// The cryptographic hash function used to generate the password.
    public let algorithm: Algorithm

    /// The number of digits in the password.
    public let digits: Int

    /**
    Initializes a new password generator with the given parameters, if valid.

    :param: factor      The moving factor
    :param: secret      The shared secret
    :param: algorithm   The cryptographic hash function (defaults to SHA-1)
    :param: digits      The number of digits in the password (defaults to 6)

    :returns: A valid password generator, or `nil` if the parameters are invalid.
    */
    public init?(factor: Factor, secret: NSData, algorithm: Algorithm = .SHA1, digits: Int = 6) {
        if !validateGenerator(factor, secret, algorithm, digits) {
            return nil
