diff options
author | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-08 14:40:53 +0000 |
---|---|---|
committer | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-08 14:40:53 +0000 |
commit | ce0a501326e20c17e76796f550179a49be67bc0f (patch) | |
tree | a620ad1268f1313da9fda613ef1c2822087d4c82 /chrome/browser/autofill | |
parent | a39aa53a7acabb03a86a5be5c663d6ae47215440 (diff) | |
download | chromium_src-ce0a501326e20c17e76796f550179a49be67bc0f.zip chromium_src-ce0a501326e20c17e76796f550179a49be67bc0f.tar.gz chromium_src-ce0a501326e20c17e76796f550179a49be67bc0f.tar.bz2 |
Putting this back in since it didn't solve the failures.
Revert 49164 - Backing this out to see if it fixes the failures on the two windows bots (landed about when they started).
Revert 49030 AutoFill: Don't save credit card numbers from Autocomplete to the WebDB.
BUG=8026
TEST=AutocompleteHistoryManagerTest
Review URL: http://codereview.chromium.org/2676003
TBR=jhawkins@chromium.org
Review URL: http://codereview.chromium.org/2748002
TBR=thomasvl@chromium.org
Review URL: http://codereview.chromium.org/2770001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49165 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r-- | chrome/browser/autofill/credit_card.cc | 52 | ||||
-rw-r--r-- | chrome/browser/autofill/credit_card.h | 7 |
2 files changed, 29 insertions, 30 deletions
diff --git a/chrome/browser/autofill/credit_card.cc b/chrome/browser/autofill/credit_card.cc index fefab77..7f41b5e 100644 --- a/chrome/browser/autofill/credit_card.cc +++ b/chrome/browser/autofill/credit_card.cc @@ -281,6 +281,31 @@ bool CreditCard::operator!=(const CreditCard& creditcard) const { return !operator==(creditcard); } +// Use the Luhn formula to validate the number. +bool CreditCard::IsCreditCardNumber(const string16& text) { + string16 number; + RemoveChars(text, kCreditCardSeparators.c_str(), &number); + + int sum = 0; + bool odd = false; + string16::reverse_iterator iter; + for (iter = number.rbegin(); iter != number.rend(); ++iter) { + if (!IsAsciiDigit(*iter)) + return false; + + int digit = *iter - '0'; + if (odd) { + digit *= 2; + sum += digit / 10 + digit % 10; + } else { + sum += digit; + } + odd = !odd; + } + + return (sum % 10) == 0; +} + string16 CreditCard::ExpirationMonthAsString() const { if (expiration_month_ == 0) return string16(); @@ -409,33 +434,6 @@ bool CreditCard::IsNameOnCard(const string16& text) const { return StringToLowerASCII(text) == StringToLowerASCII(name_on_card_); } -bool CreditCard::IsCreditCardNumber(const string16& text) { - string16 number; - TrimString(text, kCreditCardSeparators.c_str(), &number); - - // We use the Luhn formula to validate the number; see - // http://www.beachnet.com/~hstiles/cardtype.html and - // http://www.webopedia.com/TERM/L/Luhn_formula.html. - int sum = 0; - bool odd = false; - string16::reverse_iterator iter; - for (iter = number.rbegin(); iter != number.rend(); ++iter) { - if (!IsAsciiDigit(*iter)) - return false; - - int digit = *iter - '0'; - if (odd) { - digit *= 2; - sum += digit / 10 + digit % 10; - } else { - sum += digit; - } - odd = !odd; - } - - return (sum % 10) == 0; -} - bool CreditCard::IsVerificationCode(const string16& text) const { return StringToLowerASCII(text) == StringToLowerASCII(verification_code_); } diff --git a/chrome/browser/autofill/credit_card.h b/chrome/browser/autofill/credit_card.h index 4c16ec7..50bfa3a 100644 --- a/chrome/browser/autofill/credit_card.h +++ b/chrome/browser/autofill/credit_card.h @@ -58,6 +58,10 @@ class CreditCard : public FormGroup { bool operator!=(const CreditCard& creditcard) const; void set_label(const string16& label) { label_ = label; } + // Returns true if |value| is a credit card number. Uses the Luhn formula to + // validate the number. + static bool IsCreditCardNumber(const string16& text); + private: // The month and year are zero if not present. int Expiration4DigitYear() const { return expiration_year_; } @@ -107,9 +111,6 @@ class CreditCard : public FormGroup { // case-insensitive. bool IsNameOnCard(const string16& text) const; - // Uses the Luhn formula to validate the credit card number in |text|. - static bool IsCreditCardNumber(const string16& text); - // Returns true if |text| matches the expiration month of the card. bool IsExpirationMonth(const string16& text) const; |