MediaWiki REL1_28
Pbkdf2Password.php
Go to the documentation of this file.
1<?php
32 protected function getDefaultParams() {
33 return [
34 'algo' => $this->config['algo'],
35 'rounds' => $this->config['cost'],
36 'length' => $this->config['length']
37 ];
38 }
39
40 protected function getDelimiter() {
41 return ':';
42 }
43
44 public function crypt( $password ) {
45 if ( count( $this->args ) == 0 ) {
46 $this->args[] = base64_encode( MWCryptRand::generate( 16, true ) );
47 }
48
49 if ( function_exists( 'hash_pbkdf2' ) ) {
50 $hash = hash_pbkdf2(
51 $this->params['algo'],
52 $password,
53 base64_decode( $this->args[0] ),
54 (int)$this->params['rounds'],
55 (int)$this->params['length'],
56 true
57 );
58 if ( !is_string( $hash ) ) {
59 throw new PasswordError( 'Error when hashing password.' );
60 }
61 } else {
62 $hashLenHash = hash( $this->params['algo'], '', true );
63 if ( !is_string( $hashLenHash ) ) {
64 throw new PasswordError( 'Error when hashing password.' );
65 }
66 $hashLen = strlen( $hashLenHash );
67 $blockCount = ceil( $this->params['length'] / $hashLen );
68
69 $hash = '';
70 $salt = base64_decode( $this->args[0] );
71 for ( $i = 1; $i <= $blockCount; ++$i ) {
72 $roundTotal = $lastRound = hash_hmac(
73 $this->params['algo'],
74 $salt . pack( 'N', $i ),
75 $password,
76 true
77 );
78
79 for ( $j = 1; $j < $this->params['rounds']; ++$j ) {
80 $lastRound = hash_hmac( $this->params['algo'], $lastRound, $password, true );
81 $roundTotal ^= $lastRound;
82 }
83
84 $hash .= $roundTotal;
85 }
86
87 $hash = substr( $hash, 0, $this->params['length'] );
88 }
89
90 $this->hash = base64_encode( $hash );
91 }
92}
static generate( $bytes, $forceStrong=false)
Generate a run of (ideally) cryptographically random data and return it in raw binary form.
Helper class for password hash types that have a delimited set of parameters inside of the hash.
Show an error when any operation involving passwords fails to run.
string $hash
String representation of the hash without the type.
Definition Password.php:76
A PBKDF2-hashed password.
crypt( $password)
Hash a password and store the result in this object.
getDefaultParams()
Return an ordered array of default parameters for this password hash.
getDelimiter()
Returns the delimiter for the parameters inside the hash.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37