     let kProfileImagePropertyKey = "profileImage"
     let keychainPropertyKeys = ["externalId", "gender", "birthdate", "profileImage"]
     
+    let kDeprecatedUsernamePropertyKey = "email"
+    
     public var sessionToken: String? {
         get {
             return getKeychainObject(kSessionTokenKey) as? String

    
    public var password: String? {
        get {
            return getProfileObject(profileKey: SBAProfileInfoOption.password.rawValue, appCoreKey: kPasswordPropertyKey) as? String
        }
        set (newValue) {
            setProfileObject(newValue as NSSecureCoding?, profileKey: SBAProfileInfoOption.password.rawValue, appCoreKey: kPasswordPropertyKey)
        }
    }

    public var gender: HKBiologicalSex {
        get {
            let rawValue = getProfileObject(profileKey: SBAProfileInfoOption.gender.rawValue, appCoreKey: kGenderKey)


    public var email: String? {
        get {
            // For reverse-compatibility, look at both the username key and the deprecated username key
            // If found in the deprecated, write to the username value so that it will become readonly
            // for use in logging in to the server. Because this will be very noisey in the debug log 
            // and will lock the keychain, store the username in local memory and use that if available.
            if _username != nil {
                return _username
            }
            guard let username = getKeychainObject(kUsernamePropertyKey) as? String
            else {
                let email = getKeychainObject(kDeprecatedUsernamePropertyKey) as? String
                if email != nil {
                    setKeychainObject(email as NSSecureCoding?, key: kUsernamePropertyKey)
                }
                _username = email
                return email
            }
            _username = username
            return username
        }
        set (newValue) {
            // Special-case email to both set the profile and keychain. The profile may include a read/write version of 
            // the email for contact that is *not* the same email used as the username during registration.
            _username = newValue
            setKeychainObject(newValue as NSSecureCoding?, key: kUsernamePropertyKey)
            setProfileObject(newValue as NSSecureCoding?, profileKey: SBAProfileInfoOption.email.rawValue, appCoreKey: nil)
        }
    }
    private var _username: String?
    
    public var externalId: String? {
        get {
