| 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/password_generator.h" | 5 #include "components/autofill/core/browser/password_generator.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <vector> | 8 #include <vector> | 
| 9 | 9 | 
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 79     : password_length_(GetLengthFromHint(max_length, kDefaultPasswordLength)) {} | 79     : password_length_(GetLengthFromHint(max_length, kDefaultPasswordLength)) {} | 
| 80 PasswordGenerator::~PasswordGenerator() {} | 80 PasswordGenerator::~PasswordGenerator() {} | 
| 81 | 81 | 
| 82 std::string PasswordGenerator::Generate() const { | 82 std::string PasswordGenerator::Generate() const { | 
| 83   char password[255]; | 83   char password[255]; | 
| 84   char unused_hypenated_password[255]; | 84   char unused_hypenated_password[255]; | 
| 85   // Generate passwords that have numbers and upper and lower case letters. | 85   // Generate passwords that have numbers and upper and lower case letters. | 
| 86   // No special characters included for now. | 86   // No special characters included for now. | 
| 87   unsigned int mode = S_NB | S_CL | S_SL; | 87   unsigned int mode = S_NB | S_CL | S_SL; | 
| 88 | 88 | 
| 89   // gen_pron_pass() doesn't guarantee that it includes all of the type given | 89   // Generate the password by gen_pron_pass(), if it is not conforming then | 
| 90   // in mode, so regenerate a few times if neccessary. | 90   // force fix it. | 
| 91   // TODO(gcasto): Is it worth regenerating at all? | 91   gen_pron_pass(password, unused_hypenated_password, password_length_, | 
| 92   for (int i = 0; i < 10; ++i) { | 92                 password_length_, mode); | 
| 93     gen_pron_pass(password, unused_hypenated_password, |  | 
| 94                   password_length_, password_length_, mode); |  | 
| 95     if (VerifyPassword(password)) |  | 
| 96       return std::string(password); |  | 
| 97   } |  | 
| 98 | 93 | 
| 99   // If the password still isn't conforming after a few iterations, force it |  | 
| 100   // to be so. This may change a syllable in the password. |  | 
| 101   std::string str_password(password); | 94   std::string str_password(password); | 
| 102   if (!VerifyPassword(str_password)) { | 95   if (VerifyPassword(str_password)) | 
| 103     ForceFixPassword(&str_password); | 96     return str_password; | 
| 104   } | 97 | 
|  | 98   ForceFixPassword(&str_password); | 
| 105   return str_password; | 99   return str_password; | 
| 106 } | 100 } | 
| 107 | 101 | 
| 108 }  // namespace autofill | 102 }  // namespace autofill | 
| OLD | NEW | 
|---|