OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #import "ios/chrome/browser/passwords/password_controller.h" | 5 #import "ios/chrome/browser/passwords/password_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 | 684 |
685 // Determine which password is the main one, and which is | 685 // Determine which password is the main one, and which is |
686 // an old password (e.g on a "make new password" form), if any. | 686 // an old password (e.g on a "make new password" form), if any. |
687 // TODO(crbug.com/564578): Make this compatible with other platforms. | 687 // TODO(crbug.com/564578): Make this compatible with other platforms. |
688 switch (passwordCount) { | 688 switch (passwordCount) { |
689 case 1: | 689 case 1: |
690 form->password_element = elements[0]; | 690 form->password_element = elements[0]; |
691 form->password_value = values[0]; | 691 form->password_value = values[0]; |
692 break; | 692 break; |
693 case 2: { | 693 case 2: { |
694 if (values[0] == values[1]) { | 694 if (!values[0].empty() && values[0] == values[1]) { |
695 // Treat two identical passwords as a single password. | 695 // Treat two identical passwords as a single password new password, with |
| 696 // confirmation. This can be either be a sign-up form or a password |
| 697 // change form that does not ask for a new password. |
| 698 form->new_password_element = elements[0]; |
| 699 form->new_password_value = values[0]; |
| 700 } else { |
| 701 // Assume first is old password, second is new (no choice but to guess). |
696 form->password_element = elements[0]; | 702 form->password_element = elements[0]; |
697 form->password_value = values[0]; | 703 form->password_value = values[0]; |
698 } else { | 704 form->new_password_element = elements[1]; |
699 // Assume first is old password, second is new (no choice but to guess). | 705 form->new_password_value = values[1]; |
700 form->new_password_element = elements[0]; | |
701 form->new_password_value = values[0]; | |
702 form->password_element = elements[1]; | |
703 form->password_value = values[1]; | |
704 } | 706 } |
705 break; | 707 break; |
706 default: | 708 default: |
707 if (values[0] == values[1] && values[0] == values[2]) { | 709 if (!values[0].empty() && values[0] == values[1] && |
708 // All three passwords the same? Just treat as one and hope. | 710 values[0] == values[2]) { |
| 711 // All three passwords the same? This does not make sense, do not |
| 712 // add the password element. |
| 713 break; |
| 714 } else if (values[0] == values[1]) { |
| 715 // First two the same and the third different implies that the old |
| 716 // password is the duplicated one. |
709 form->password_element = elements[0]; | 717 form->password_element = elements[0]; |
710 form->password_value = values[0]; | 718 form->password_value = values[0]; |
711 } else if (values[0] == values[1]) { | 719 form->new_password_element = elements[2]; |
712 // Two the same and one different -> old password is the duplicated | 720 form->new_password_value = values[2]; |
713 // one. | |
714 form->new_password_element = elements[0]; | |
715 form->new_password_value = values[0]; | |
716 form->password_element = elements[2]; | |
717 form->password_value = values[2]; | |
718 } else if (values[1] == values[2]) { | 721 } else if (values[1] == values[2]) { |
719 // Two the same and one different -> new password is the duplicated | 722 // Two the same and one different -> new password is the duplicated |
720 // one. | 723 // one. |
721 form->new_password_element = elements[0]; | 724 form->password_element = elements[0]; |
722 form->new_password_value = values[0]; | 725 form->password_value = values[0]; |
723 form->password_element = elements[1]; | 726 form->new_password_element = elements[1]; |
724 form->password_value = values[1]; | 727 form->new_password_value = values[1]; |
725 } else { | 728 } else { |
726 // Three different passwords, or first and last match with middle | 729 // Three different passwords, or first and last match with middle |
727 // different. No idea which is which, so no luck. | 730 // different. No idea which is which, so no luck. |
728 } | 731 } |
729 break; | 732 break; |
730 } | 733 } |
731 } | 734 } |
732 | 735 |
733 // Fill in as much data about the fields as is required for password | 736 // Fill in as much data about the fields as is required for password |
734 // generation. | 737 // generation. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 | 826 |
824 - (PasswordManager*)passwordManager { | 827 - (PasswordManager*)passwordManager { |
825 return passwordManager_.get(); | 828 return passwordManager_.get(); |
826 } | 829 } |
827 | 830 |
828 - (JsPasswordManager*)passwordJsManager { | 831 - (JsPasswordManager*)passwordJsManager { |
829 return passwordJsManager_; | 832 return passwordJsManager_; |
830 } | 833 } |
831 | 834 |
832 @end | 835 @end |
OLD | NEW |