Rock.Model.UserLoginService.SetPassword C# (CSharp) Метод

SetPassword() публичный Метод

Sets the a UserLogin's password.
public SetPassword ( UserLogin user, string password ) : void
user UserLogin The to change the password for.
password string A representing the new password.
Результат void
        public void SetPassword( UserLogin user, string password )
        {
            var entityType = EntityTypeCache.Read( user.EntityTypeId ?? 0);

            var authenticationComponent = AuthenticationContainer.GetComponent( entityType.Name );
            if ( authenticationComponent == null || !authenticationComponent.IsActive )
                throw new Exception( string.Format( "'{0}' service does not exist, or is not active", entityType.FriendlyName ) );

            if ( authenticationComponent.ServiceType == AuthenticationServiceType.External )
                throw new Exception( "Cannot change password on external service type" );

            authenticationComponent.SetPassword( user, password );
            user.LastPasswordChangedDateTime = RockDateTime.Now;
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Authenticates the specified user name and password
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public override bool Authenticate( UserLogin user, string password )
        {
            var passwordIsCorrect = CheckF1Password( user.UserName, password );

            if ( passwordIsCorrect )
            {
                using ( var rockContext = new RockContext() )
                {
                    var userLoginService = new UserLoginService( rockContext );
                    var userFromService = userLoginService.Get( user.Id );
                    var databaseGuid = Rock.SystemGuid.EntityType.AUTHENTICATION_DATABASE.AsGuid();
                    userFromService.EntityTypeId = EntityTypeCache.Read( databaseGuid ).Id;
                    userLoginService.SetPassword( userFromService, password );
                    rockContext.SaveChanges();
                }
            }

            return passwordIsCorrect;
        }
All Usage Examples Of Rock.Model.UserLoginService::SetPassword