Commit graph

11 commits

Author SHA1 Message Date
Alexander Vorwerk
1bfde4aef9 EncryptedPassword: Store default parameters as strings
Currently ->needsUpdate always returns true since it compares 0 as an
integer to "0" as a string strictly, which fails.

This means that on every successful login the user password hash is
newly generated and stored in the db, causing unnecessary writes to the
user table.

Also cast params['secret'] to int since that is read from the stored
password hash and thus will be a string and is already being implicitly
casted.

Bug: T366130
Change-Id: Icad0dcf15d5889f8cc7941a7ea7bf250ee30f47c
2024-06-01 23:21:41 +00:00
Reedy
5ab70409f5 Namespace includes/password
Bug: T353458
Change-Id: I1a701b5b7ff65356692abb0efde9a2207b6135b6
2024-05-18 16:17:38 +01:00
Alexander Vorwerk
763c5cdfd5 Make EncryptedPassword work with Argon2Password
Currently EncryptPassword doesn't work, because it just uses ->verify()
from the Password class. That method does just regenerate the hash of
the password provided and then checks whether they match.

The problem is that in the case of Argon2 being the underlying hashing
algorithm the salt is not known and PHP is just going to generate a new
one while regenerating the hash (in order to compare it then) and thus
the hashes are not going to match making logins fail.

So instead lets just decrypt the stored password hash and then use the
corresponding ->verify() method from the underlying Password type.

Bug: T150647
Bug: T216682
Change-Id: I053aade9dcaf156a26f2f6bebd17773c4df30b9c
2024-05-08 20:22:25 +00:00
Daimona Eaytoy
1d6776fdbc Replace deprecated MWException
Also remove some unchecked exception from doc comments.

Bug: T328220
Bug: T240672
Change-Id: I88b1e948ce5da77d9c4862a2b98793d6ba00cf8b
2024-01-19 21:58:42 +00:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Max Semenik
b86088857a Use strict types in includes/password
This is a well isolated area of code, without functions that are
likely to receive PHP's trademark "garbage in, garbage out" data
as parameters. Capitalize on this and require strict types there.

Change-Id: I9f1c172e737018d058ddc1700d8234832b58efa6
2019-11-19 15:01:09 +00:00
Max Semenik
9bab7de5f8 Clean up CSPRNG support for PHP7
Replace it all with random_bytes(), leave
only MWCryptRand::generateHex() as a convenience helper.

Change-Id: Ic30376a90e66d8f00dab86e7e6466fb3a750b87d
2018-06-10 00:52:04 +00:00
Tim Starling
6dbb8f2d78 Fix multiple bugs in EncryptedPassword
* openssl_decrypt() expects the encrypted string you give it to be the
  exact one that came out of openssl_encrypt(), it doesn't expect you to
  pre-decode the base64 encoding. So don't do that.
* Use the same IV when re-encrypting the underlying hash for comparison.
* Check the return value of OpenSSL functions, and report meaningful
  error messages, for sysadmin convenience and to avoid e.g. giving all
  users the same hash if an invalid cipher method was chosen (which was
  the previous behaviour).
* Fix EncryptedPassword::update(). Tested it with eval.php since there
  doesn't seem to be any callers.

Change-Id: I3a39de152d0329f93d16aa4ed43faf08f665b8e2
2016-11-15 15:15:24 +11:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
jeroendedauw
ce7912b22a Remove dead argument in EncryptedPassword.php
Change-Id: Ib0bb2733284262c233e6de4c7645f0b215690156
2015-09-16 17:03:35 +00:00
Tyler Anthony Romeo
95a8974c6b
Added password hashing API
Deprecated the old User::crypt, et. al password hashing
system and implemented an extensible password hashing
API.

The new Password class allows registering of child classes
and provides factory functions for creating new Password
objects. The built-in hash types are the old MediaWiki MD5
types, which are for backwards-compatibility only, and bcrypt.

Also included is support for wrapping existing hashes as well
as encrypting passwords with a configured encryption key.

Bug: 54948
Bug: 28419
Change-Id: I0a9c972931a0eff0cfb2619cef3ddffd03710285
2014-07-27 15:51:18 -04:00