Version: current

# Class PasswordEncryptor

Allows pluggable password encryption. By default, this might be PHP's integrated sha1() function, but could also be more sophisticated to facilitate password migrations from other systems. Use `PasswordEncryptor::register()` to add new implementations.

Used in `Security::encrypt_password()`.

### Direct known subclasses

`PasswordEncryptor_MySQLOldPassword`, `PasswordEncryptor_MySQLPassword`, `PasswordEncryptor_None`, `PasswordEncryptor_PHPHash`

### Indirect known subclasses

`PasswordEncryptor_LegacyPHPHash`

Abstract
Package: sapphire\security
Located at sapphire/security/PasswordEncryptor.php

## Methods summary

`public static Array` | # `get_encryptors( )` #### Returns `Array` Map of encryptor code to the used class.
`public static` | # `register( String $code, String $class )` Add a new encryptor implementation. Add a new encryptor implementation. Note: Due to portability concerns, its not advisable to override an existing $code mapping with different behaviour. #### Parameters $code String $code This value will be stored stored in the Member->PasswordEncryption property. $class String $class Classname of a `PasswordEncryptor` subclass
`public static` | # `unregister( String $code )` #### Parameters $code String $code Unique lookup.
`public static `PasswordEncryptor`|`Boolean`` | # `create_for_algorithm( String $algorithm )` #### Parameters $algorithm String $algorithm #### Returns ``PasswordEncryptor`|`Boolean`` Returns FALSE if class was not found
`abstract public String` | # `encrypt( String $password, String $salt = null, `Member` $member = null )` Return a string value stored in the Member->Password property. The password should be hashed with `PasswordEncryptor::salt()` if applicable. Return a string value stored in the Member->Password property. The password should be hashed with `PasswordEncryptor::salt()` if applicable. #### Parameters $password String $password Cleartext password to be hashed $salt String $salt (Optional) $member Member $member (Optional) #### Returns `String` Maximum of 512 characters.
`public String` | # `salt( String $password, `Member` $member = null )` Return a string value stored in the Member->Salt property. By default uses sha1() and mt_rand(); Return a string value stored in the Member->Salt property. By default uses sha1() and mt_rand(); Note: Only used when `Security::$useSalt` is TRUE. #### Parameters $password String $password Cleartext password $member Member $member (Optional) #### Returns `String` Maximum of 50 characters
`public boolean` | # `compare( String $hash1, String $hash2 )` This usually just returns a strict string comparison, but is necessary for `PasswordEncryptor_LegacyPHPHash`. This usually just returns a strict string comparison, but is necessary for `PasswordEncryptor_LegacyPHPHash`. #### Parameters $hash1 String $hash1 $hash2 String $hash2 #### Returns `boolean` boolean

### Magic methods summary

## Properties summary

`protected static array` | $encryptors | #

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -