9 $this->assertEquals( [
'' ], array_keys( $pf->getTypes() ) );
10 $this->assertEquals(
'', $pf->getDefaultType() );
13 'foo' => [
'class' =>
'FooPassword' ],
14 'bar' => [
'class' =>
'BarPassword',
'baz' =>
'boom' ],
16 $this->assertEquals( [
'',
'foo',
'bar' ], array_keys( $pf->getTypes() ) );
17 $this->assertArraySubset( [
'class' =>
'BarPassword',
'baz' =>
'boom' ], $pf->getTypes()[
'bar'] );
18 $this->assertEquals(
'foo', $pf->getDefaultType() );
23 $pf->
register(
'foo', [
'class' => InvalidPassword::class ] );
24 $this->assertArrayHasKey(
'foo', $pf->getTypes() );
29 $pf->
register(
'1', [
'class' => InvalidPassword::class ] );
30 $pf->register(
'2', [
'class' => InvalidPassword::class ] );
31 $pf->setDefaultType(
'1' );
32 $this->assertSame(
'1', $pf->getDefaultType() );
33 $pf->setDefaultType(
'2' );
34 $this->assertSame(
'2', $pf->getDefaultType() );
48 'foo' => [
'class' => InvalidPassword::class ],
50 'PasswordDefault' =>
'foo'
54 $this->assertSame(
'foo', $pf->getDefaultType() );
55 $this->assertArrayHasKey(
'foo', $pf->getTypes() );
60 $pf->
register(
'B', [
'class' => MWSaltedPassword::class ] );
61 $pw = $pf->newFromCiphertext(
':B:salt:d529e941509eb9e9b9cfaeae1fe7ca23' );
62 $this->assertInstanceOf( MWSaltedPassword::class, $pw );
66 return [ [
'blah' ], [
':blah:' ] ];
75 $pf->
register(
'B', [
'class' => MWSaltedPassword::class ] );
76 $pf->newFromCiphertext( $hash );
81 $pf->
register(
'B', [
'class' => MWSaltedPassword::class ] );
82 $pw = $pf->newFromType(
'B' );
83 $this->assertInstanceOf( MWSaltedPassword::class, $pw );
91 $pf->
register(
'B', [
'class' => MWSaltedPassword::class ] );
92 $pf->newFromType(
'bogus' );
97 $pf->
register(
'A', [
'class' => MWOldPassword::class ] );
98 $pf->register(
'B', [
'class' => MWSaltedPassword::class ] );
99 $pf->setDefaultType(
'A' );
101 $this->assertInstanceOf( InvalidPassword::class, $pf->newFromPlaintext(
null ) );
102 $this->assertInstanceOf( MWOldPassword::class, $pf->newFromPlaintext(
'password' ) );
103 $this->assertInstanceOf( MWSaltedPassword::class,
104 $pf->newFromPlaintext(
'password', $pf->newFromType(
'B' ) ) );
109 $pf->
register(
'A', [
'class' => MWOldPassword::class ] );
110 $pf->register(
'B', [
'class' => MWSaltedPassword::class ] );
111 $pf->setDefaultType(
'A' );
113 $this->assertFalse( $pf->needsUpdate( $pf->newFromType(
'A' ) ) );
114 $this->assertTrue( $pf->needsUpdate( $pf->newFromType(
'B' ) ) );
118 $this->assertSame( 13, strlen( PasswordFactory::generateRandomPasswordString( 13 ) ) );
122 $this->assertInstanceOf( InvalidPassword::class, PasswordFactory::newInvalidPassword() );
A Config instance which stores all settings as a member variable.
testNewFromCiphertextErrors( $hash)
provideNewFromCiphertextErrors PasswordError
testNewFromTypeError()
PasswordError.
testSetDefaultTypeError()
Exception.
provideNewFromCiphertextErrors()
testGenerateRandomPasswordString()
Factory class for creating and checking Password objects.
register( $type, array $config)
Register a new type of password hash.
setDefaultType( $type)
Set the default password type.