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 "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 bool IsValidCreditCardExpirationDate(const base::string16& year, | 27 bool IsValidCreditCardExpirationDate(const base::string16& year, |
28 const base::string16& month, | 28 const base::string16& month, |
29 const base::Time& now) { | 29 const base::Time& now) { |
30 base::string16 year_cleaned, month_cleaned; | 30 base::string16 year_cleaned, month_cleaned; |
31 TrimWhitespace(year, TRIM_ALL, &year_cleaned); | 31 TrimWhitespace(year, TRIM_ALL, &year_cleaned); |
32 TrimWhitespace(month, TRIM_ALL, &month_cleaned); | 32 TrimWhitespace(month, TRIM_ALL, &month_cleaned); |
33 if (year_cleaned.length() != 4) | 33 if (year_cleaned.length() != 4) |
34 return false; | 34 return false; |
35 | 35 |
| 36 int cc_year; |
| 37 if (!base::StringToInt(year_cleaned, &cc_year)) |
| 38 return false; |
| 39 |
| 40 int cc_month; |
| 41 if (!base::StringToInt(month_cleaned, &cc_month)) |
| 42 return false; |
| 43 |
| 44 return IsValidCreditCardExpirationDate(cc_year, cc_month, now); |
| 45 } |
| 46 |
| 47 bool IsValidCreditCardExpirationDate(int year, |
| 48 int month, |
| 49 const base::Time& now) { |
36 base::Time::Exploded now_exploded; | 50 base::Time::Exploded now_exploded; |
37 now.LocalExplode(&now_exploded); | 51 now.LocalExplode(&now_exploded); |
38 size_t current_year = size_t(now_exploded.year); | |
39 size_t current_month = size_t(now_exploded.month); | |
40 | 52 |
41 size_t cc_year; | 53 if (year < now_exploded.year) |
42 if (!base::StringToSizeT(year_cleaned, &cc_year)) | |
43 return false; | |
44 if (cc_year < current_year) | |
45 return false; | 54 return false; |
46 | 55 |
47 size_t cc_month; | 56 if (year == now_exploded.year && month < now_exploded.month) |
48 if (!base::StringToSizeT(month_cleaned, &cc_month)) | |
49 return false; | |
50 if (cc_year == current_year && cc_month < current_month) | |
51 return false; | 57 return false; |
52 | 58 |
53 return true; | 59 return true; |
54 } | 60 } |
55 | 61 |
56 bool IsValidCreditCardNumber(const base::string16& text) { | 62 bool IsValidCreditCardNumber(const base::string16& text) { |
57 base::string16 number = CreditCard::StripSeparators(text); | 63 base::string16 number = CreditCard::StripSeparators(text); |
58 | 64 |
59 // Credit card numbers are at most 19 digits in length [1]. 12 digits seems to | 65 // Credit card numbers are at most 19 digits in length [1]. 12 digits seems to |
60 // be a fairly safe lower-bound [2]. | 66 // be a fairly safe lower-bound [2]. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 number_string.begin() + 9), | 193 number_string.begin() + 9), |
188 &serial) | 194 &serial) |
189 || serial == 0) { | 195 || serial == 0) { |
190 return false; | 196 return false; |
191 } | 197 } |
192 | 198 |
193 return true; | 199 return true; |
194 } | 200 } |
195 | 201 |
196 } // namespace autofill | 202 } // namespace autofill |
OLD | NEW |