throw new MWException( "Passed User has not been added to the database yet!" );
}
+ if ( $user->checkPassword( $password ) === true ) {
+ return; // Nothing to do.
+ }
+
$passwordFactory = new PasswordFactory();
$passwordFactory->init( RequestContext::getMain()->getConfig() );
- // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
- $passwordFactory->setDefaultType( 'A' );
- $pwhash = $passwordFactory->newFromPlaintext( $password );
+ $passwordHash = $passwordFactory->newFromPlaintext( $password );
wfGetDB( DB_MASTER )->update(
'user',
- [ 'user_password' => $pwhash->toString() ],
+ [ 'user_password' => $passwordHash->toString() ],
[ 'user_id' => $user->getId() ],
__METHOD__
);
$passwordFactory = new PasswordFactory();
$passwordFactory->init( RequestContext::getMain()->getConfig() );
// A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
- $passwordFactory->setDefaultType( 'A' );
- $pwhash = $passwordFactory->newFromPlaintext( 'foobaz' );
+ $passwordHash = $passwordFactory->newFromPlaintext( 'foobaz' );
$dbw = wfGetDB( DB_MASTER );
$dbw->insert(
[
'bp_user' => $centralId,
'bp_app_id' => 'foo',
- 'bp_password' => $pwhash->toString(),
+ 'bp_password' => $passwordHash->toString(),
'bp_token' => '',
'bp_restrictions' => MWRestrictions::newDefault()->toJson(),
'bp_grants' => '["test"]',
public function addDBDataOnce() {
$passwordFactory = new \PasswordFactory();
$passwordFactory->init( \RequestContext::getMain()->getConfig() );
- // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
- $passwordFactory->setDefaultType( 'A' );
- $pwhash = $passwordFactory->newFromPlaintext( 'foobaz' );
+ $passwordHash = $passwordFactory->newFromPlaintext( 'foobaz' );
$userId = \CentralIdLookup::factory( 'local' )->centralIdFromName( 'UTSysop' );
[
'bp_user' => $userId,
'bp_app_id' => 'BotPasswordSessionProvider',
- 'bp_password' => $pwhash->toString(),
+ 'bp_password' => $passwordHash->toString(),
'bp_token' => 'token!',
'bp_restrictions' => '{"IPAddresses":["127.0.0.0/8"]}',
'bp_grants' => '["test"]',
public function addDBData() {
$passwordFactory = new \PasswordFactory();
$passwordFactory->init( \RequestContext::getMain()->getConfig() );
- // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
- $passwordFactory->setDefaultType( 'A' );
- $pwhash = $passwordFactory->newFromPlaintext( 'foobaz' );
+ $passwordHash = $passwordFactory->newFromPlaintext( 'foobaz' );
$dbw = wfGetDB( DB_MASTER );
$dbw->delete(
[
'bp_user' => 42,
'bp_app_id' => 'BotPassword',
- 'bp_password' => $pwhash->toString(),
+ 'bp_password' => $passwordHash->toString(),
'bp_token' => 'token!',
'bp_restrictions' => '{"IPAddresses":["127.0.0.0/8"]}',
'bp_grants' => '["test"]',
[
'bp_user' => 43,
'bp_app_id' => 'BotPassword',
- 'bp_password' => $pwhash->toString(),
+ 'bp_password' => $passwordHash->toString(),
'bp_token' => 'token!',
'bp_restrictions' => '{"IPAddresses":["127.0.0.0/8"]}',
'bp_grants' => '["test"]',
public function testSave( $password ) {
$passwordFactory = new \PasswordFactory();
$passwordFactory->init( \RequestContext::getMain()->getConfig() );
- // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
- $passwordFactory->setDefaultType( 'A' );
$bp = BotPassword::newUnsaved( [
'centralId' => 42,
BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST ), 'sanity check'
);
- $pwhash = $password ? $passwordFactory->newFromPlaintext( $password ) : null;
- $this->assertFalse( $bp->save( 'update', $pwhash ) );
- $this->assertTrue( $bp->save( 'insert', $pwhash ) );
+ $passwordHash = $password ? $passwordFactory->newFromPlaintext( $password ) : null;
+ $this->assertFalse( $bp->save( 'update', $passwordHash ) );
+ $this->assertTrue( $bp->save( 'insert', $passwordHash ) );
$bp2 = BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST );
$this->assertInstanceOf( 'BotPassword', $bp2 );
$this->assertEquals( $bp->getUserCentralId(), $bp2->getUserCentralId() );
$this->assertTrue( $pw->equals( $password ) );
}
- $pwhash = $passwordFactory->newFromPlaintext( 'XXX' );
+ $passwordHash = $passwordFactory->newFromPlaintext( 'XXX' );
$token = $bp->getToken();
- $this->assertTrue( $bp->save( 'update', $pwhash ) );
+ $this->assertTrue( $bp->save( 'update', $passwordHash ) );
$this->assertNotEquals( $token, $bp->getToken() );
$pw = TestingAccessWrapper::newFromObject( $bp )->getPassword();
$this->assertTrue( $pw->equals( 'XXX' ) );