Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/validation.h" | 5 #include "components/autofill/core/browser/validation.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 | 42 |
| 43 return true; | 43 return true; |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool IsValidCreditCardNumber(const base::string16& text) { | 46 bool IsValidCreditCardNumber(const base::string16& text) { |
| 47 base::string16 number = CreditCard::StripSeparators(text); | 47 base::string16 number = CreditCard::StripSeparators(text); |
| 48 | 48 |
| 49 // Credit card numbers are at most 19 digits in length [1]. 12 digits seems to | 49 // Credit card numbers are at most 19 digits in length [1]. 12 digits seems to |
| 50 // be a fairly safe lower-bound [2]. Specific card issuers have more rigidly | 50 // be a fairly safe lower-bound [2]. Specific card issuers have more rigidly |
| 51 // defined sizes. | 51 // defined sizes. |
| 52 // [1] http://www.merriampark.com/anatomycc.htm | 52 // [1] http://www.merriampark.com/anatomycc.htm |
|
Jared Saul
2017/05/26 19:51:10
This link is broken; the last known good snapshot
jiahuiguo
2017/05/29 20:08:06
The link in wiki is sufficient I believe, and note
| |
| 53 // [2] http://en.wikipedia.org/wiki/Bank_card_number | 53 // [2] http://en.wikipedia.org/wiki/Bank_card_number |
|
Jared Saul
2017/05/26 19:51:10
This has also changed to Payment_card_number; upda
jiahuiguo
2017/05/29 20:08:06
Done.
| |
| 54 // CardEditor.isCardNumberLengthMaxium() needs to be kept in sync. | 54 // CardEditor.isCardNumberLengthMaxium() needs to be kept in sync. |
| 55 const char* const type = CreditCard::GetCardNetwork(text); | 55 const char* const type = CreditCard::GetCardNetwork(text); |
| 56 if (type == kAmericanExpressCard && number.size() != 15) | 56 if (type == kAmericanExpressCard && number.size() != 15) |
| 57 return false; | 57 return false; |
| 58 if (type == kDinersCard && number.size() != 14) | 58 if (type == kDinersCard && number.size() != 14) |
| 59 return false; | 59 return false; |
| 60 if (type == kDiscoverCard && number.size() != 16) | 60 if (type == kDiscoverCard && number.size() != 16) |
| 61 return false; | 61 return false; |
| 62 if (type == kEloCard && number.size() != 16) | |
| 63 return false; | |
| 62 if (type == kJCBCard && number.size() != 16) | 64 if (type == kJCBCard && number.size() != 16) |
| 63 return false; | 65 return false; |
| 64 if (type == kMasterCard && number.size() != 16) | 66 if (type == kMasterCard && number.size() != 16) |
| 65 return false; | 67 return false; |
| 66 if (type == kMirCard && number.size() != 16) | 68 if (type == kMirCard && number.size() != 16) |
| 67 return false; | 69 return false; |
| 68 if (type == kUnionPay && (number.size() < 16 || number.size() > 19)) | 70 if (type == kUnionPay && (number.size() < 16 || number.size() > 19)) |
| 69 return false; | 71 return false; |
| 70 if (type == kVisaCard && number.size() != 13 && number.size() != 16) | 72 if (type == kVisaCard && number.size() != 13 && number.size() != 16 && |
| 73 number.size() != 19) | |
| 71 return false; | 74 return false; |
| 72 if (type == kGenericCard && (number.size() < 12 || number.size() > 19)) | 75 if (type == kGenericCard && (number.size() < 12 || number.size() > 19)) |
| 73 return false; | 76 return false; |
| 74 | 77 |
| 75 // Use the Luhn formula [3] to validate the number. | 78 // Use the Luhn formula [3] to validate the number. |
| 76 // [3] http://en.wikipedia.org/wiki/Luhn_algorithm | 79 // [3] http://en.wikipedia.org/wiki/Luhn_algorithm |
| 77 int sum = 0; | 80 int sum = 0; |
| 78 bool odd = false; | 81 bool odd = false; |
| 79 for (base::string16::reverse_iterator iter = number.rbegin(); | 82 for (base::string16::reverse_iterator iter = number.rbegin(); |
| 80 iter != number.rend(); | 83 iter != number.rend(); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 return AMEX_CVC_LENGTH; | 379 return AMEX_CVC_LENGTH; |
| 377 | 380 |
| 378 return GENERAL_CVC_LENGTH; | 381 return GENERAL_CVC_LENGTH; |
| 379 } | 382 } |
| 380 | 383 |
| 381 bool IsUPIVirtualPaymentAddress(const base::string16& value) { | 384 bool IsUPIVirtualPaymentAddress(const base::string16& value) { |
| 382 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe)); | 385 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe)); |
| 383 } | 386 } |
| 384 | 387 |
| 385 } // namespace autofill | 388 } // namespace autofill |
| OLD | NEW |