Android Open Source - PassPlus pass Gen






From Project

Back to project page PassPlus.

License

The source code is released under:

Apache License

If you think the Android project PassPlus listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.diragi.passplus;
//from   w  ww .j a  v a  2 s  .co  m
import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.EditText;
import android.view.View;
import android.widget.NumberPicker;
import android.widget.Toast;

import java.security.SecureRandom;
import java.util.Random;

public class passGen extends themeCheck {
    NumberPicker lengthChooser;
    SharedPreferences mPrefs;

    @Override
    public void finOnCreate() {
        mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
        String theme = mPrefs.getString("pref_themeColor", "0");
        setContentView(R.layout.activity_passgen);
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
        mPrefs = PreferenceManager.getDefaultSharedPreferences(this);


    }

    public static String randomPassString(char[] characterSet, int length) {

        Random randPass = new SecureRandom();
        char[] result = new char[length];
        for (int i = 0; i <result.length; i++) {

            //pick random index out of character set
            int randomCharIndex = randPass.nextInt(characterSet.length);
            result[i] = characterSet[randomCharIndex];

        }

        return new String(result);
    }

    public void genPass(View v) {
        EditText genPass = (EditText)findViewById(R.id.genPass);
        int length;
        EditText passLength = (EditText)findViewById(R.id.titleText);
        char[] CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".toCharArray();
        CheckBox symbolsOrNah = (CheckBox)findViewById(R.id.checkBox);

        if (symbolsOrNah.isChecked()) {

            CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*".toCharArray();

        }

        if (passLength.getText().toString().length() == 0) {

            length = 10;

        } else {

            length = Integer.parseInt(passLength.getText().toString());

        }

        if (length > 45) {

            Toast.makeText(getApplicationContext(), "Length cannot be longer than 45", Toast.LENGTH_SHORT).show();

        } else if (length == 0) {

            Toast.makeText(getApplicationContext(), "Length cannot be '0'", Toast.LENGTH_SHORT).show();

        } else {

            String generatedPass = randomPassString(CHARSET, length);
            genPass.setText(generatedPass);

        }




    }

    public void makefontsnotshit(){
        EditText text1 = (EditText)findViewById(R.id.titleText);
        EditText text2 = (EditText)findViewById(R.id.genPass);

        text1.setTypeface(Typeface.DEFAULT);
        text2.setTypeface(Typeface.DEFAULT);
    }

}




Java Source Code List

com.diragi.passplus.AboutActivity.java
com.diragi.passplus.ApplicationTest.java
com.diragi.passplus.BackupAgent.java
com.diragi.passplus.Backup.java
com.diragi.passplus.DriveBackup.java
com.diragi.passplus.Encrypt2.java
com.diragi.passplus.SettingsActivity.java
com.diragi.passplus.Upgrade.java
com.diragi.passplus.util.Base64DecoderException.java
com.diragi.passplus.util.Base64.java
com.diragi.passplus.util.IabException.java
com.diragi.passplus.util.IabHelper.java
com.diragi.passplus.util.IabResult.java
com.diragi.passplus.util.Inventory.java
com.diragi.passplus.util.Purchase.java
com.diragi.passplus.util.Security.java
com.diragi.passplus.util.SkuDetails.java
com.diragi.passplus.add.java
com.diragi.passplus.first.java
com.diragi.passplus.forgot.java
com.diragi.passplus.lock.java
com.diragi.passplus.main.java
com.diragi.passplus.passGen.java
com.diragi.passplus.passView.java
com.diragi.passplus.themeCheckPref.java
com.diragi.passplus.themeCheck.java