mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-10-31 18:47:33 +08:00 
			
		
		
		
	Fix #18904: Improve Captcha client-side validation
This commit is contained in:
		| @ -20,6 +20,7 @@ Yii Framework 2 Change Log | |||||||
| - Bug #18883: Fix `yii\web\HeaderCollection::fromArray()` now ensures lower case keys (rhertogh) | - Bug #18883: Fix `yii\web\HeaderCollection::fromArray()` now ensures lower case keys (rhertogh) | ||||||
| - Bug #18886: Fix default return of `yii\db\Migration::safeUp()` and `yii\db\Migration::safeDown()` (WinterSilence) | - Bug #18886: Fix default return of `yii\db\Migration::safeUp()` and `yii\db\Migration::safeDown()` (WinterSilence) | ||||||
| - Bug #18898: Fix `yii\helpers\Inflector::camel2words()` to work with words ending with 0 (michaelarnauts) | - Bug #18898: Fix `yii\helpers\Inflector::camel2words()` to work with words ending with 0 (michaelarnauts) | ||||||
|  | - Enh #18904: Improve Captcha client-side validation (hexkir) | ||||||
|  |  | ||||||
|  |  | ||||||
| 2.0.43 August 09, 2021 | 2.0.43 August 09, 2021 | ||||||
|  | |||||||
| @ -261,7 +261,7 @@ yii.validation = (function ($) { | |||||||
|             hash = hash == null ? options.hash : hash[options.caseSensitive ? 0 : 1]; |             hash = hash == null ? options.hash : hash[options.caseSensitive ? 0 : 1]; | ||||||
|             var v = options.caseSensitive ? value : value.toLowerCase(); |             var v = options.caseSensitive ? value : value.toLowerCase(); | ||||||
|             for (var i = v.length - 1, h = 0; i >= 0; --i) { |             for (var i = v.length - 1, h = 0; i >= 0; --i) { | ||||||
|                 h += v.charCodeAt(i); |                 h += v.charCodeAt(i) << i; | ||||||
|             } |             } | ||||||
|             if (h != hash) { |             if (h != hash) { | ||||||
|                 pub.addMessage(messages, options.message, value); |                 pub.addMessage(messages, options.message, value); | ||||||
|  | |||||||
| @ -150,7 +150,7 @@ class CaptchaAction extends Action | |||||||
|     public function generateValidationHash($code) |     public function generateValidationHash($code) | ||||||
|     { |     { | ||||||
|         for ($h = 0, $i = strlen($code) - 1; $i >= 0; --$i) { |         for ($h = 0, $i = strlen($code) - 1; $i >= 0; --$i) { | ||||||
|             $h += ord($code[$i]); |             $h += ord($code[$i]) << $i; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return $h; |         return $h; | ||||||
|  | |||||||
| @ -1307,7 +1307,7 @@ describe('yii.validation', function () { | |||||||
|  |  | ||||||
|     describe('captcha validator', function () { |     describe('captcha validator', function () { | ||||||
|         // Converted using yii\captcha\CaptchaAction generateValidationHash() method |         // Converted using yii\captcha\CaptchaAction generateValidationHash() method | ||||||
|         var hashes = {'Code': 379, 'code': 411}; |         var hashes = {'Code': 1497, 'code': 1529}; | ||||||
|         var caseInSensitiveData = { |         var caseInSensitiveData = { | ||||||
|             'valid code in lowercase': ['code', true], |             'valid code in lowercase': ['code', true], | ||||||
|             'valid code in uppercase': ['CODE', true], |             'valid code in uppercase': ['CODE', true], | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 hexkir
					hexkir