diff --git a/res/layout/entry_edit.xml b/res/layout/entry_edit.xml
index 37853f653..b0b4f8c18 100644
--- a/res/layout/entry_edit.xml
+++ b/res/layout/entry_edit.xml
@@ -91,19 +91,24 @@
android:layout_height="wrap_content"
android:layout_below="@id/entry_url"
android:text="@string/entry_password" />
+
+ android:layout_toLeftOf="@id/generate_button"
+ android:hint="@string/hint_pass"
+ android:layout_alignTop="@id/generate_button"/>
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:layout_below="@id/entry_password" android:text="@string/entry_confpassword" />
-
+
+
\ No newline at end of file
diff --git a/res/layout/generate_password.xml b/res/layout/generate_password.xml
new file mode 100644
index 000000000..f119235e8
--- /dev/null
+++ b/res/layout/generate_password.xml
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f294e5cba..12ea52074 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -23,6 +23,7 @@
OK
KeePassDroid is an Android implementation of the KeePass password manager.
Twitter:
+ Accept
Add entry
Add group
Add Group
@@ -33,6 +34,7 @@
Time before locking database when the application is inactive.
Application
Application settings
+ Brackets
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.
Building search index...
Cancel
@@ -47,6 +49,7 @@
Database
Decrypting database contents...
Decrypting entry
+ Digits
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.
Enter database filename:
Accessed:
@@ -77,17 +80,22 @@
A name is required.
A password or a keyfile is required.
The phone ran out of memory while parsing your database. It may be too large for your phone.
+ At least one password generation type must be selected
Passwords do not match.
Rounds must be a number.
Rounds too big. Setting to 2147483648.
A title is required.
+ Enter a positive integer on length field
File not found.
File Browser
+ Generate Password
Group
comment
confirm password
+ generated password
Group name
key file
+ length
password
name
url
@@ -96,9 +104,11 @@
Install from Web
Invalid password or key file.
Database format not recognized.
+ Length
Group list size
Text size in the group list
Loading database...
+ Lower-case
*****
Mask password
Hide passwords by default
@@ -119,6 +129,7 @@
Rename
Search
Go to URL
+ Minus
Never
No entries in the database or group.
No search results
@@ -138,13 +149,17 @@
Higher encryption rounds provide additional protection against brute force attacks, but can really slow down loading and saving.
rounds
Saving database...
- Sort by name
- DB sort order
- Entry title/description
+ Space
Search
Show password
+ Sort by name
+ DB sort order
+ Special
+ Entry title/description
Twofish
+ Underline
Unsupported database version.
+ Upper-case
Your sd card is currently read-only. You may not be able to save changes to your database.
Your sd card is not currently mounted on your device. You will not be able to load or create your database.
diff --git a/src/com/keepassdroid/EntryEditActivity.java b/src/com/keepassdroid/EntryEditActivity.java
index f8f47a0d5..3930a4d7b 100644
--- a/src/com/keepassdroid/EntryEditActivity.java
+++ b/src/com/keepassdroid/EntryEditActivity.java
@@ -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) {
diff --git a/src/com/keepassdroid/GeneratePasswordActivity.java b/src/com/keepassdroid/GeneratePasswordActivity.java
new file mode 100644
index 000000000..6cb51dc9b
--- /dev/null
+++ b/src/com/keepassdroid/GeneratePasswordActivity.java
@@ -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;
+ }
+}
diff --git a/src/com/keepassdroid/password/PasswordGenerator.java b/src/com/keepassdroid/password/PasswordGenerator.java
new file mode 100644
index 000000000..8cb07f21d
--- /dev/null
+++ b/src/com/keepassdroid/password/PasswordGenerator.java
@@ -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();
+ }
+}