Back to project page PasswordDroid.
The source code is released under:
GNU General Public License
If you think the Android project PasswordDroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package de.wuthoehle.passworddroid; //from w w w.ja v a2 s. c o m /* Copyright (c) 2015 Marco Huenseler <marcoh.huenseler+git@gmail.com> * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import de.wuthoehle.passworddroid.crypto.DerivationRunnableFactory; import de.wuthoehle.passworddroid.crypto.SCryptParameters.SCryptParametersFactory; import de.wuthoehle.passworddroid.crypto.Util; import de.wuthoehle.passworddroid.service.model.Category; import de.wuthoehle.passworddroid.service.model.entries.Customizable; import de.wuthoehle.passworddroid.service.model.entries.DerivatorEntry; import de.wuthoehle.passworddroid.service.model.entries.Entry; import de.wuthoehle.passworddroid.service.model.entries.EntryFactory; import de.wuthoehle.passworddroid.service.model.entries.WriteVisitor; public class PasswordDerivateActivity extends ActionBarActivity { private DerivationRunnableFactory entryderivation; private EditText master, globalsalt, localsalt, entrylen; private CheckBox upper, lower, numbers, special; private TextView result; private List<DerivatorEntry> current_queue = new ArrayList<>(); private Map<Integer, List<DerivatorEntry>> thread_map = new HashMap<>(); private Handler derivation_handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); int id = msg.getData().getInt("id"); int type = msg.getData().getInt("type"); switch (type) { case DerivationRunnableFactory.MESSAGE_TYPE_DONE: List<DerivatorEntry> entries = thread_map.get(id); List<String> passwords = msg.getData().getStringArrayList("passwordList"); String newtext = result.getText().toString(); for (int i = 0; i < passwords.size(); i++) { newtext += '\n' + entries.get(i).getName() + ": " + passwords.get(i); } result.setText(newtext); break; case DerivationRunnableFactory.MESSAGE_TYPE_STATUS: result.setText(result.getText().toString() + '\n' + msg.getData().getInt("done") + "/" + msg.getData().getInt("total")); break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_password_derivate); master = (EditText) findViewById(R.id.vedit_master); globalsalt = (EditText) findViewById(R.id.vedit_globalsalt); localsalt = (EditText) findViewById(R.id.vedit_localsalt); entrylen = (EditText) findViewById(R.id.veditnr_pwlen); upper = (CheckBox) findViewById(R.id.vcheck_upper); lower = (CheckBox) findViewById(R.id.vcheck_lower); numbers = (CheckBox) findViewById(R.id.vcheck_nr); special = (CheckBox) findViewById(R.id.vcheck_special); result = (TextView) findViewById(R.id.vtext_results); ((Button) findViewById(R.id.vbutton_masterok)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setGlobals(); } }); ((Button) findViewById(R.id.vbutton_add)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { addToQueue(); } }); ((Button) findViewById(R.id.vbutton_calc)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { calculate(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_password_derivate, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { ((TextView) findViewById(R.id.vtext_results)).setText(""); current_queue.clear(); return true; } return super.onOptionsItemSelected(item); } public final void setGlobals() { List<String> salts = new ArrayList<>(1); salts.add(globalsalt.getText().toString()); try { entryderivation = new DerivationRunnableFactory( master.getText().toString(), salts, SCryptParametersFactory.getSCryptParameters(SCryptParametersFactory.SCRYPT_TEMPLATE_STRONG), derivation_handler ); } catch (GeneralSecurityException e) { e.printStackTrace(); } } public final void addToQueue() { List<String> salts = new ArrayList<>(1); salts.add(localsalt.getText().toString()); byte mask = 0; if (upper.isChecked()) mask |= Customizable.ID_UPPER_CASE; if (lower.isChecked()) mask |= Customizable.ID_LOWER_CASE; if (numbers.isChecked()) mask |= Customizable.ID_NUMBERS; if (special.isChecked()) mask |= Customizable.ID_SPECIAL; DerivatorEntry new_entry = new DerivatorEntry( salts.get(0).substring(0, 3), // Service Name "myusr", // User Name new Category(), // Category 0, // Counter mask, // CharMask "", // Additional Characters Integer.parseInt(entrylen.getText().toString()), // PW length "no comment", // Comment salts // Additional Salts ); WriteVisitor visitor = new WriteVisitor(); new_entry.accept(visitor); LinkedList<Byte> entry_list = visitor.getWriteList(); String eins = Util.byteListToString(entry_list); EntryFactory givetheentry = new EntryFactory(entry_list, new Category()); givetheentry.parseEntry(); Entry copied = givetheentry.getEntry(); WriteVisitor visitor2 = new WriteVisitor(); copied.accept(visitor2); String zwei = Util.byteListToString(visitor2.getWriteList()); current_queue.add(new_entry); result.setText(result.getText().toString() + '\n' + current_queue.size() + " elements in queue now." + '\n' + "Latest entry: " + eins + '\n' + "Compare w /: " + zwei); } public final void calculate() { if (entryderivation == null) { Toast.makeText(this, "Set master pw first!", Toast.LENGTH_SHORT).show(); } else { int id = thread_map.size(); thread_map.put(id, Util.cloneList(current_queue)); DerivatorEntry[] entries = new DerivatorEntry[current_queue.size()]; for (int i = 0; i < current_queue.size(); i++) { entries[i] = current_queue.get(i); } current_queue.clear(); new Thread(entryderivation.getRunnable(id, entries)).start(); } } }