Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: components/autofill/core/browser/validation.cc

Issue 2906763005: Add support for Brazil Elo card in autofill. (Closed)
Patch Set: Fix test Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 28 matching lines...) Expand all
39 39
40 if (year == now_exploded.year && month < now_exploded.month) 40 if (year == now_exploded.year && month < now_exploded.month)
41 return false; 41 return false;
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, 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 [1]. Specific card issuers have more rigidly
51 // defined sizes. 51 // defined sizes.
52 // [1] http://www.merriampark.com/anatomycc.htm 52 // (Last updated: May 29, 2017)
53 // [2] http://en.wikipedia.org/wiki/Bank_card_number 53 // [1] https://en.wikipedia.org/wiki/Payment_card_number.
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698