Allow to enter password only once in Entry Edit Activity

This commit is contained in:
Philipp Crocoll 2014-03-16 03:04:23 +01:00
parent a26f908bd8
commit d7b6490c2f
5 changed files with 126 additions and 124 deletions

View File

@ -242,13 +242,15 @@ namespace keepass2android
}; };
// Respect mask password setting // Respect mask password setting
if (State.ShowPassword) { MakePasswordVisibleOrHidden();
EditText pass = (EditText) FindViewById(Resource.Id.entry_password);
EditText conf = (EditText) FindViewById(Resource.Id.entry_confpassword); ImageButton btnTogglePassword = (ImageButton)FindViewById(Resource.Id.toggle_password);
btnTogglePassword.Click += (sender, e) =>
{
State.ShowPassword = !State.ShowPassword;
MakePasswordVisibleOrHidden();
};
pass.InputType = InputTypes.ClassText | InputTypes.TextVariationVisiblePassword;
conf.InputType = InputTypes.ClassText | InputTypes.TextVariationVisiblePassword;
}
Button addButton = (Button) FindViewById(Resource.Id.add_advanced); Button addButton = (Button) FindViewById(Resource.Id.add_advanced);
addButton.Visibility = ViewStates.Visible; addButton.Visibility = ViewStates.Visible;
@ -283,6 +285,22 @@ namespace keepass2android
} }
private void MakePasswordVisibleOrHidden()
{
TextView password = (TextView) FindViewById(Resource.Id.entry_password);
TextView confpassword = (TextView) FindViewById(Resource.Id.entry_confpassword);
if (State.ShowPassword)
{
password.InputType = InputTypes.ClassText | InputTypes.TextVariationVisiblePassword;
confpassword.Visibility = ViewStates.Gone;
}
else
{
password.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword;
confpassword.Visibility = ViewStates.Visible;
}
}
void SaveEntry() void SaveEntry()
{ {
Database db = App.Kp2a.GetDb(); Database db = App.Kp2a.GetDb();
@ -685,13 +703,6 @@ namespace keepass2android
inflater.Inflate(Resource.Menu.entry_edit, menu); inflater.Inflate(Resource.Menu.entry_edit, menu);
IMenuItem togglePassword = menu.FindItem(Resource.Id.menu_toggle_pass);
if ( State.ShowPassword ) {
togglePassword.SetTitle(Resource.String.menu_hide_password);
} else {
togglePassword.SetTitle(Resource.String.show_password);
}
return true; return true;
} }
@ -705,16 +716,6 @@ namespace keepass2android
return false; return false;
} }
return true;
case Resource.Id.menu_toggle_pass:
if ( State.ShowPassword ) {
item.SetTitle(Resource.String.show_password);
State.ShowPassword = false;
} else {
item.SetTitle(Resource.String.menu_hide_password);
State.ShowPassword = true;
}
SetPasswordStyle();
return true; return true;
case Resource.Id.menu_cancel_edit: case Resource.Id.menu_cancel_edit:
Finish(); Finish();
@ -748,19 +749,6 @@ namespace keepass2android
return base.OnOptionsItemSelected(item); return base.OnOptionsItemSelected(item);
} }
private void SetPasswordStyle() {
TextView password = (TextView) FindViewById(Resource.Id.entry_password);
TextView confpassword = (TextView) FindViewById(Resource.Id.entry_confpassword);
if ( State.ShowPassword ) {
password.InputType = InputTypes.ClassText | InputTypes.TextVariationVisiblePassword;
confpassword.InputType = InputTypes.ClassText | InputTypes.TextVariationVisiblePassword;
} else {
password.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword;
confpassword.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword;
}
}
void UpdateExpires() void UpdateExpires()
{ {
@ -862,7 +850,6 @@ namespace keepass2android
String password = State.Entry.Strings.ReadSafe(PwDefs.PasswordField); String password = State.Entry.Strings.ReadSafe(PwDefs.PasswordField);
PopulateText(Resource.Id.entry_password, password); PopulateText(Resource.Id.entry_password, password);
PopulateText(Resource.Id.entry_confpassword, password); PopulateText(Resource.Id.entry_confpassword, password);
SetPasswordStyle();
PopulateText(Resource.Id.entry_comment, State.Entry.Strings.ReadSafe (PwDefs.NotesField)); PopulateText(Resource.Id.entry_comment, State.Entry.Strings.ReadSafe (PwDefs.NotesField));
@ -913,14 +900,19 @@ namespace keepass2android
return false; return false;
} }
// Validate password if (!State.ShowPassword)
String pass = Util.GetEditText(this, Resource.Id.entry_password); {
String conf = Util.GetEditText(this, Resource.Id.entry_confpassword); // Validate password
if ( ! pass.Equals(conf) ) { String pass = Util.GetEditText(this, Resource.Id.entry_password);
Toast.MakeText(this, Resource.String.error_pass_match, ToastLength.Long).Show(); String conf = Util.GetEditText(this, Resource.Id.entry_confpassword);
return false; if (!pass.Equals(conf))
{
Toast.MakeText(this, Resource.String.error_pass_match, ToastLength.Long).Show();
return false;
}
} }
// Validate expiry date // Validate expiry date
DateTime newExpiry = new DateTime(); DateTime newExpiry = new DateTime();
if ((State.Entry.Expires) && (!DateTime.TryParse( Util.GetEditText(this,Resource.Id.entry_expires), out newExpiry))) if ((State.Entry.Expires) && (!DateTime.TryParse( Util.GetEditText(this,Resource.Id.entry_expires), out newExpiry)))

View File

@ -57,49 +57,57 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/entry_url" android:layout_below="@id/entry_url"
android:text="@string/entry_password" /> android:text="@string/entry_password" />
<Button <RelativeLayout
android:id="@+id/generate_button" android:id="@+id/password_section"
android:layout_width="wrap_content" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_below="@id/entry_password_label">
android:layout_below="@id/entry_password_label"
android:text="@string/ellipsis" /> <Button
<EditText android:id="@+id/generate_button"
android:id="@+id/entry_password" android:layout_width="wrap_content"
style="@style/TextAppearance_EditEntry_Value" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:layout_alignParentRight="true"
android:layout_height="wrap_content" android:text="@string/ellipsis" />
android:layout_alignTop="@id/generate_button" <ImageButton
android:layout_toLeftOf="@id/generate_button" android:id="@+id/toggle_password"
android:hint="@string/hint_pass" android:layout_width="wrap_content"
android:inputType="textPassword" android:layout_height="wrap_content"
android:singleLine="true" android:src="@drawable/ic_menu_view"
android:typeface="monospace" /> android:layout_alignTop="@id/generate_button"
<!-- Confirm Password --> android:layout_toLeftOf="@id/generate_button"
<TextView />
android:id="@+id/entry_confpassword_label" <EditText
style="@style/TextAppearance_EditEntry_LabelSmall" android:id="@+id/entry_password"
android:layout_width="wrap_content" style="@style/TextAppearance_EditEntry_Value"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_below="@id/entry_password" android:layout_height="wrap_content"
android:text="@string/entry_confpassword" /> android:layout_alignTop="@id/generate_button"
<EditText android:layout_toLeftOf="@id/toggle_password"
android:id="@+id/entry_confpassword" android:hint="@string/hint_pass"
style="@style/TextAppearance_EditEntry_Value" android:inputType="textPassword"
android:layout_width="fill_parent" android:singleLine="true"
android:layout_height="wrap_content" android:typeface="monospace" />
android:layout_below="@id/entry_confpassword_label" <!-- Confirm Password -->
android:hint="@string/hint_conf_pass" <EditText
android:inputType="textPassword" android:id="@+id/entry_confpassword"
android:singleLine="true" style="@style/TextAppearance_EditEntry_Value"
android:typeface="monospace" /> android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/entry_password"
android:hint="@string/hint_conf_pass"
android:inputType="textPassword"
android:singleLine="true"
android:typeface="monospace" />
</RelativeLayout>
<!-- Comment --> <!-- Comment -->
<TextView <TextView
android:id="@+id/entry_comment_label" android:id="@+id/entry_comment_label"
style="@style/TextAppearance_EditEntry_LabelSmall" style="@style/TextAppearance_EditEntry_LabelSmall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/entry_confpassword" android:layout_below="@id/password_section"
android:text="@string/entry_comment" /> android:text="@string/entry_comment" />
<EditText <EditText
android:id="@+id/entry_comment" android:id="@+id/entry_comment"

View File

@ -95,45 +95,56 @@
android:layout_below="@id/entry_url" android:layout_below="@id/entry_url"
style="@style/EntryFieldHeader" style="@style/EntryFieldHeader"
android:text="@string/entry_password" /> android:text="@string/entry_password" />
<Button <RelativeLayout
android:id="@+id/generate_button" android:id="@+id/password_section"
android:layout_below="@id/entry_password_label" android:layout_width="fill_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/ellipsis" android:layout_below="@id/entry_password_label">
android:layout_height="wrap_content"
android:layout_alignParentRight="true" /> <Button
<EditText android:id="@+id/generate_button"
android:id="@+id/entry_password" android:layout_width="wrap_content"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true"
android:inputType="textPassword" android:text="@string/ellipsis" />
android:typeface="monospace" <ImageButton
android:singleLine="true" android:id="@+id/toggle_password"
android:layout_toLeftOf="@id/generate_button" android:layout_width="wrap_content"
android:hint="@string/hint_pass" android:layout_height="wrap_content"
android:layout_alignTop="@id/generate_button" /> android:src="@drawable/ic_menu_view"
<!-- Confirm Password --> android:layout_alignTop="@id/generate_button"
<TextView android:layout_toLeftOf="@id/generate_button"
android:id="@+id/entry_confpassword_label" />
android:layout_width="wrap_content" <EditText
android:layout_height="wrap_content" android:id="@+id/entry_password"
android:layout_below="@id/entry_password" style="@style/TextAppearance_EditEntry_Value"
android:text="@string/entry_confpassword" /> android:layout_width="fill_parent"
<EditText android:layout_height="wrap_content"
android:id="@+id/entry_confpassword" android:layout_alignTop="@id/generate_button"
android:layout_width="fill_parent" android:layout_toLeftOf="@id/toggle_password"
android:layout_height="wrap_content" android:hint="@string/hint_pass"
android:inputType="textPassword" android:inputType="textPassword"
android:typeface="monospace" android:singleLine="true"
android:singleLine="true" android:typeface="monospace" />
android:layout_below="@id/entry_confpassword_label" <!-- Confirm Password -->
android:hint="@string/hint_conf_pass" /> <EditText
android:id="@+id/entry_confpassword"
style="@style/TextAppearance_EditEntry_Value"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/entry_password"
android:hint="@string/hint_conf_pass"
android:inputType="textPassword"
android:singleLine="true"
android:typeface="monospace" />
</RelativeLayout>
<!-- Comment --> <!-- Comment -->
<TextView <TextView
android:id="@+id/entry_comment_label" android:id="@+id/entry_comment_label"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/entry_confpassword" android:layout_below="@id/password_section"
style="@style/EntryFieldHeader" style="@style/EntryFieldHeader"
android:text="@string/entry_comment" /> android:text="@string/entry_comment" />
<EditText <EditText

View File

@ -16,11 +16,6 @@
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>. along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
--> -->
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_toggle_pass"
android:title="@string/show_password"
android:icon="@android:drawable/ic_menu_view"
android:showAsAction="ifRoom"
/>
<item android:id="@+id/menu_donate" <item android:id="@+id/menu_donate"
android:title="@string/menu_donate" android:title="@string/menu_donate"
android:showAsAction="ifRoom" android:showAsAction="ifRoom"

View File

@ -17,10 +17,6 @@
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>. along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
--> -->
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_toggle_pass"
android:icon="@android:drawable/ic_menu_view"
android:title="@string/show_password"
/>
<item android:id="@+id/menu_cancel_edit" <item android:id="@+id/menu_cancel_edit"
android:title="@string/entry_cancel" android:title="@string/entry_cancel"
/> />