mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-24 02:51:34 -08:00
Password generator patch from Tolga Onbay.
This commit is contained in:
1 parent
372bd3e059
commit
5e81f721cf
6 files changed
+367
-10
No files matched your search
@@ -91,19 +91,24 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/entry_url"
|
||||
android:text="@string/entry_password" />
|
||||
<Button android:id="@+id/generate_button"
|
||||
android:layout_below="@id/entry_password_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:text=". . ."
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"/>
|
||||
<EditText android:id="@+id/entry_password"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:password="true"
|
||||
android:singleLine="true"
|
||||
android:layout_below="@id/entry_password_label"
|
||||
android:hint="@string/hint_pass"/>
|
||||
android:layout_toLeftOf="@id/generate_button"
|
||||
android:hint="@string/hint_pass"
|
||||
android:layout_alignTop="@id/generate_button"/>
|
||||
<!-- Confirm Password -->
|
||||
<TextView android:id="@+id/entry_confpassword_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/entry_password"
|
||||
android:text="@string/entry_confpassword" />
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:layout_below="@id/entry_password" android:text="@string/entry_confpassword" />
|
||||
<EditText android:id="@+id/entry_confpassword"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -123,6 +128,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/entry_comment_label"
|
||||
android:hint="@string/hint_comment"/>
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
||||
</RelativeLayout>
|
||||
@@ -0,0 +1,120 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<Button android:id="@+id/accept_button"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/accept"
|
||||
android:layout_alignParentBottom="true" />
|
||||
<Button android:id="@+id/cancel_button"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/cancel"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_toRightOf="@id/accept_button" />
|
||||
<ScrollView android:id="@+id/ScrollView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@id/cancel_button">
|
||||
<RelativeLayout android:id="@+id/RelativeLayout"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/ScrollView"
|
||||
android:layout_width="wrap_content">
|
||||
<TextView android:id="@+id/length_label"
|
||||
android:text="@string/length"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent" />
|
||||
<Button android:id="@+id/btn_length16"
|
||||
android:text="16"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:width="38px"
|
||||
android:layout_below="@id/length_label" />
|
||||
<Button android:id="@+id/btn_length12"
|
||||
android:text="12"
|
||||
android:layout_toLeftOf="@id/btn_length16"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:width="38px"
|
||||
android:layout_alignTop="@id/btn_length16" />
|
||||
<Button android:id="@+id/btn_length8"
|
||||
android:text="8"
|
||||
android:layout_toLeftOf="@id/btn_length12"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:width="38px"
|
||||
android:layout_alignTop="@id/btn_length16" />
|
||||
<Button android:id="@+id/btn_length6"
|
||||
android:text="6"
|
||||
android:layout_toLeftOf="@id/btn_length8"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:width="38px"
|
||||
android:layout_alignTop="@id/btn_length16" />
|
||||
<Button android:id="@+id/btn_length4"
|
||||
android:text="4"
|
||||
android:layout_toLeftOf="@id/btn_length6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:width="38px"
|
||||
android:layout_alignTop="@id/btn_length16" />
|
||||
<EditText android:id="@+id/length"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_toLeftOf="@id/btn_length4"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@id/btn_length16"
|
||||
android:hint="@string/hint_length"/>
|
||||
<CheckBox android:id="@+id/cb_uppercase"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/uppercase"
|
||||
android:layout_below="@id/length" />
|
||||
<CheckBox android:id="@+id/cb_lowercase"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/lowercase"
|
||||
android:layout_below="@id/cb_uppercase" />
|
||||
<CheckBox android:id="@+id/cb_digits"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/digits"
|
||||
android:layout_below="@id/cb_lowercase" />
|
||||
<CheckBox android:id="@+id/cb_minus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/minus"
|
||||
android:layout_below="@id/cb_digits" />
|
||||
<CheckBox android:id="@+id/cb_underline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/underline"
|
||||
android:layout_below="@id/cb_minus" />
|
||||
<CheckBox android:id="@+id/cb_space"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/space"
|
||||
android:layout_below="@id/cb_underline" />
|
||||
<CheckBox android:id="@+id/cb_specials"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/special"
|
||||
android:layout_below="@id/cb_space" />
|
||||
<CheckBox android:id="@+id/cb_brackets"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/brackets"
|
||||
android:layout_below="@id/cb_specials" />
|
||||
<EditText android:id="@+id/password"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_below="@id/cb_brackets"
|
||||
android:hint="@string/hint_generated_password" />
|
||||
<Button android:id="@+id/generate_password_button"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:text="@string/generate_password"
|
||||
android:layout_below="@id/password" />
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
||||
</RelativeLayout>
|
||||
+18
-3
@@ -23,6 +23,7 @@
|
||||
<string name="about_ok">OK</string>
|
||||
<string name="AboutText">KeePassDroid is an Android implementation of the KeePass password manager.</string>
|
||||
<string name="about_twitter">Twitter:</string>
|
||||
<string name="accept">Accept</string>
|
||||
<string name="add_entry">Add entry</string>
|
||||
<string name="add_group">Add group</string>
|
||||
<string name="add_group_title">Add Group</string>
|
||||
@@ -33,6 +34,7 @@
|
||||
<string name="app_timeout_summary">Time before locking database when the application is inactive.</string>
|
||||
<string name="application">Application</string>
|
||||
<string name="application_settings">Application settings</string>
|
||||
<string name="brackets">Brackets</string>
|
||||
<string name="browser_intall_text">File browsing requires the Open Intents File Manager, click below to install it. Due to some quirks in the file manager, browsing may not work correctly, the first time you browse.</string>
|
||||
<string name="building_search_idx">Building search index...</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
@@ -47,6 +49,7 @@
|
||||
<string name="database">Database</string>
|
||||
<string name="decrypting_db">Decrypting database contents...</string>
|
||||
<string name="decrypting_entry">Decrypting entry</string>
|
||||
<string name="digits">Digits</string>
|
||||
<string name="disclaimer_formal">KeePassDroid Copyright 2009 Brian Pellin comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it under the conditions of the GPL version 2 or later.</string>
|
||||
<string name="enter_filename">Enter database filename:</string>
|
||||
<string name="entry_accessed">Accessed: </string>
|
||||
@@ -77,17 +80,22 @@
|
||||
<string name="error_no_name">A name is required.</string>
|
||||
<string name="error_nopass">A password or a keyfile is required.</string>
|
||||
<string name="error_out_of_memory">The phone ran out of memory while parsing your database. It may be too large for your phone.</string>
|
||||
<string name="error_pass_gen_type">At least one password generation type must be selected</string>
|
||||
<string name="error_pass_match">Passwords do not match.</string>
|
||||
<string name="error_rounds_not_number">Rounds must be a number.</string>
|
||||
<string name="error_rounds_too_large">Rounds too big. Setting to 2147483648.</string>
|
||||
<string name="error_title_required">A title is required.</string>
|
||||
<string name="error_wrong_length">Enter a positive integer on length field</string>
|
||||
<string name="FileNotFound">File not found.</string>
|
||||
<string name="file_browser">File Browser</string>
|
||||
<string name="generate_password">Generate Password</string>
|
||||
<string name="group">Group</string>
|
||||
<string name="hint_comment">comment</string>
|
||||
<string name="hint_conf_pass">confirm password</string>
|
||||
<string name="hint_generated_password">generated password</string>
|
||||
<string name="hint_group_name">Group name</string>
|
||||
<string name="hint_keyfile">key file</string>
|
||||
<string name="hint_length">length</string>
|
||||
<string name="hint_pass">password</string>
|
||||
<string name="hint_title">name</string>
|
||||
<string name="hint_url">url</string>
|
||||
@@ -96,9 +104,11 @@
|
||||
<string name="install_from_website">Install from Web</string>
|
||||
<string name="InvalidPassword">Invalid password or key file.</string>
|
||||
<string name="invalid_db_sig">Database format not recognized.</string>
|
||||
<string name="length">Length</string>
|
||||
<string name="list_size_title">Group list size</string>
|
||||
<string name="list_size_summary">Text size in the group list</string>
|
||||
<string name="loading_database">Loading database...</string>
|
||||
<string name="lowercase">Lower-case</string>
|
||||
<string name="MaskedPassword">*****</string>
|
||||
<string name="maskpass_title">Mask password</string>
|
||||
<string name="maskpass_summary">Hide passwords by default</string>
|
||||
@@ -119,6 +129,7 @@
|
||||
<string name="menu_rename">Rename</string>
|
||||
<string name="menu_search">Search</string>
|
||||
<string name="menu_url">Go to URL</string>
|
||||
<string name="minus">Minus</string>
|
||||
<string name="never">Never</string>
|
||||
<string name="no_keys">No entries in the database or group.</string>
|
||||
<string name="no_results">No search results</string>
|
||||
@@ -138,13 +149,17 @@
|
||||
<string name="rounds_explaination">Higher encryption rounds provide additional protection against brute force attacks, but can really slow down loading and saving.</string>
|
||||
<string name="rounds_hint">rounds</string>
|
||||
<string name="saving_database">Saving database...</string>
|
||||
<string name="sort_name">Sort by name</string>
|
||||
<string name="sort_db">DB sort order</string>
|
||||
<string name="search_hint">Entry title/description</string>
|
||||
<string name="space">Space</string>
|
||||
<string name="search_label">Search</string>
|
||||
<string name="show_password">Show password</string>
|
||||
<string name="sort_name">Sort by name</string>
|
||||
<string name="sort_db">DB sort order</string>
|
||||
<string name="special">Special</string>
|
||||
<string name="search_hint">Entry title/description</string>
|
||||
<string name="twofish">Twofish</string>
|
||||
<string name="underline">Underline</string>
|
||||
<string name="unsupported_db_version">Unsupported database version.</string>
|
||||
<string name="uppercase">Upper-case</string>
|
||||
<string name="warning_read_only">Your sd card is currently read-only. You may not be able to save changes to your database.</string>
|
||||
<string name="warning_unmounted">Your sd card is not currently mounted on your device. You will not be able to load or create your database.</string>
|
||||
|
||||
|
||||
@@ -134,6 +134,19 @@ public class EntryEditActivity extends LockCloseActivity {
|
||||
}
|
||||
});
|
||||
|
||||
// Generate password button
|
||||
Button generatePassword = (Button) findViewById(R.id.generate_button);
|
||||
generatePassword.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//EntryEditActivity.Launch(EntryActivity.this, mEntry);
|
||||
GeneratePasswordActivity.Launch(EntryEditActivity.this);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Save button
|
||||
Button save = (Button) findViewById(R.id.entry_save);
|
||||
save.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -237,6 +250,18 @@ public class EntryEditActivity extends LockCloseActivity {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
String generatedPassword = data.getStringExtra("com.keepassdroid.password.generated_password");
|
||||
EditText password = (EditText) findViewById(R.id.entry_password);
|
||||
EditText confPassword = (EditText) findViewById(R.id.entry_confpassword);
|
||||
|
||||
password.setText(generatedPassword);
|
||||
confPassword.setText(generatedPassword);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.keepassdroid;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.keepass.KeePass;
|
||||
import com.android.keepass.R;
|
||||
import com.keepassdroid.password.PasswordGenerator;
|
||||
|
||||
public class GeneratePasswordActivity extends LockCloseActivity {
|
||||
private static final int[] BUTTON_IDS = new int [] {R.id.btn_length4, R.id.btn_length6, R.id.btn_length8, R.id.btn_length12, R.id.btn_length16};
|
||||
|
||||
public static void Launch(Activity act) {
|
||||
Intent i = new Intent(act, GeneratePasswordActivity.class);
|
||||
|
||||
act.startActivityForResult(i, 0);
|
||||
}
|
||||
|
||||
private OnClickListener lengthButtonsListener = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
Button button = (Button) v;
|
||||
|
||||
EditText editText = (EditText) findViewById(R.id.length);
|
||||
editText.setText(button.getText());
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.generate_password);
|
||||
setResult(KeePass.EXIT_NORMAL);
|
||||
|
||||
for (int id : BUTTON_IDS) {
|
||||
Button button = (Button) findViewById(id);
|
||||
button.setOnClickListener(lengthButtonsListener);
|
||||
}
|
||||
|
||||
Button genPassButton = (Button) findViewById(R.id.generate_password_button);
|
||||
genPassButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
String password = generatePassword();
|
||||
|
||||
EditText txtPassword = (EditText) findViewById(R.id.password);
|
||||
txtPassword.setText(password);
|
||||
}
|
||||
});
|
||||
|
||||
Button acceptButton = (Button) findViewById(R.id.accept_button);
|
||||
acceptButton.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
EditText password = (EditText) findViewById(R.id.password);
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("com.keepassdroid.password.generated_password", password.getText().toString());
|
||||
|
||||
setResult(RESULT_OK, intent);
|
||||
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
Button cancelButton = (Button) findViewById(R.id.cancel_button);
|
||||
cancelButton.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setResult(RESULT_CANCELED);
|
||||
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String generatePassword() {
|
||||
String password = "";
|
||||
|
||||
try {
|
||||
int length = new Integer(((EditText) findViewById(R.id.length)).getText().toString());
|
||||
|
||||
((CheckBox) findViewById(R.id.cb_uppercase)).isChecked();
|
||||
|
||||
PasswordGenerator generator = new PasswordGenerator(this);
|
||||
|
||||
password = generator.generatePassword(length,
|
||||
((CheckBox) findViewById(R.id.cb_uppercase)).isChecked(),
|
||||
((CheckBox) findViewById(R.id.cb_lowercase)).isChecked(),
|
||||
((CheckBox) findViewById(R.id.cb_digits)).isChecked(),
|
||||
((CheckBox) findViewById(R.id.cb_minus)).isChecked(),
|
||||
((CheckBox) findViewById(R.id.cb_underline)).isChecked(),
|
||||
((CheckBox) findViewById(R.id.cb_space)).isChecked(),
|
||||
((CheckBox) findViewById(R.id.cb_specials)).isChecked(),
|
||||
((CheckBox) findViewById(R.id.cb_brackets)).isChecked());
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(this, R.string.error_wrong_length, Toast.LENGTH_LONG).show();
|
||||
} catch (IllegalArgumentException e) {
|
||||
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
return password;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.keepassdroid.password;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.keepass.R;
|
||||
|
||||
public class PasswordGenerator {
|
||||
private static final String upperCaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
private static final String lowerCaseChars = "abcdefghijklmnopqrstuvwxyz";
|
||||
private static final String digitChars = "0123456789";
|
||||
private static final String minusChars = "-";
|
||||
private static final String underlineChars = "_";
|
||||
private static final String spaceChars = " ";
|
||||
private static final String specialChars = "!\"#$%&'*+,./:;=?@\\^`";
|
||||
private static final String bracketChars = "[]{}()<>";
|
||||
|
||||
private Context cxt;
|
||||
|
||||
public PasswordGenerator(Context cxt) {
|
||||
this.cxt = cxt;
|
||||
}
|
||||
|
||||
public String generatePassword(int length, boolean upperCase, boolean lowerCase, boolean digits, boolean minus, boolean underline, boolean space, boolean specials, boolean brackets) throws IllegalArgumentException{
|
||||
if (length <= 0)
|
||||
throw new IllegalArgumentException(cxt.getString(R.string.error_wrong_length));
|
||||
|
||||
if (!upperCase && !lowerCase && !digits && !minus && !underline && !space && !specials && !brackets)
|
||||
throw new IllegalArgumentException(cxt.getString(R.string.error_pass_gen_type));
|
||||
|
||||
String characterSet = getCharacterSet(upperCase, lowerCase, digits, minus, underline, space, specials, brackets);
|
||||
|
||||
int size = characterSet.length();
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
if (size > 0) {
|
||||
Random random = new Random();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = characterSet.charAt((char) random.nextInt(size));
|
||||
|
||||
buffer.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public String getCharacterSet(boolean upperCase, boolean lowerCase, boolean digits, boolean minus, boolean underline, boolean space, boolean specials, boolean brackets) {
|
||||
StringBuffer charSet = new StringBuffer();
|
||||
|
||||
if (upperCase)
|
||||
charSet.append(upperCaseChars);
|
||||
|
||||
if (lowerCase)
|
||||
charSet.append(lowerCaseChars);
|
||||
|
||||
if (digits)
|
||||
charSet.append(digitChars);
|
||||
|
||||
if (minus)
|
||||
charSet.append(minusChars);
|
||||
|
||||
if (underline)
|
||||
charSet.append(underlineChars);
|
||||
|
||||
if (space)
|
||||
charSet.append(spaceChars);
|
||||
|
||||
if (specials)
|
||||
charSet.append(specialChars);
|
||||
|
||||
if (brackets)
|
||||
charSet.append(bracketChars);
|
||||
|
||||
return charSet.toString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user