OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_AUTOFILL_PASSWORD_GENERATOR_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_PASSWORD_GENERATOR_H_ |
6 #define CHROME_BROWSER_AUTOFILL_PASSWORD_GENERATOR_H_ | 6 #define CHROME_BROWSER_AUTOFILL_PASSWORD_GENERATOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/gtest_prod_util.h" |
12 | 13 |
13 namespace autofill { | 14 namespace autofill { |
14 | 15 |
15 // Class to generate random passwords. Currently we just use a generic algorithm | 16 // Class to generate random passwords. Currently we just use a generic algorithm |
16 // for all sites, but eventually we can incorporate additional information to | 17 // for all sites, but eventually we can incorporate additional information to |
17 // determine passwords that are likely to be accepted (i.e. use pattern field, | 18 // determine passwords that are likely to be accepted (i.e. use pattern field, |
18 // previous generated passwords, crowdsourcing, etc.) | 19 // previous generated passwords, crowdsourcing, etc.) |
19 class PasswordGenerator { | 20 class PasswordGenerator { |
20 public: | 21 public: |
21 PasswordGenerator(); | 22 // |max_length| is used as a hint for the generated password's length. |
| 23 explicit PasswordGenerator(size_t max_length); |
22 ~PasswordGenerator(); | 24 ~PasswordGenerator(); |
23 | 25 |
24 // Returns a random password. The string is guaranteed to be printable and | 26 // Returns a random password such that: |
25 // will not include whitespace characters. | 27 // (1) Each character is guaranteed to be a non-whitespace printable ASCII |
26 std::string Generate(); | 28 // character. |
| 29 // (2) The generated password will contain AT LEAST one upper case letter, one |
| 30 // lower case letter, one digit, and one other symbol. |
| 31 // (3) The password length will be equal to |password_length_| (see comment |
| 32 // for the constructor). |
| 33 std::string Generate() const; |
27 | 34 |
28 private: | 35 private: |
| 36 // Unit test also need to access |kDefaultPasswordLength|. |
| 37 static const size_t kDefaultPasswordLength; |
| 38 FRIEND_TEST_ALL_PREFIXES(PasswordGeneratorTest, PasswordLength); |
| 39 |
| 40 // The length of the generated password. |
| 41 const size_t password_length_; |
29 | 42 |
30 DISALLOW_COPY_AND_ASSIGN(PasswordGenerator); | 43 DISALLOW_COPY_AND_ASSIGN(PasswordGenerator); |
31 }; | 44 }; |
32 | 45 |
33 } // namespace autofill | 46 } // namespace autofill |
34 | 47 |
35 #endif // CHROME_BROWSER_AUTOFILL_PASSWORD_GENERATOR_H_ | 48 #endif // CHROME_BROWSER_AUTOFILL_PASSWORD_GENERATOR_H_ |
OLD | NEW |