Android Open Source - KeepMySecret Side Logic






From Project

Back to project page KeepMySecret.

License

The source code is released under:

GNU General Public License

If you think the Android project KeepMySecret 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 keepmysecretapp.app.com.keepmysecretapp.fragments.other;
/*from w ww  .  j a  v  a 2  s. co m*/
import static java.lang.Math.random;

public abstract class SideLogic {

    public enum PasswordDifficult {
        EASY, MIDDLE, HARD
    }


    public static String generatePassword(PasswordDifficult difficult) {

        int interval = 6;

        StringBuilder builder = new StringBuilder();

        if (difficult.equals(PasswordDifficult.EASY))
            interval = 6;
        else if (difficult.equals(PasswordDifficult.MIDDLE))
            interval = 12;
        else if (difficult.equals(PasswordDifficult.HARD))
            interval = 18;

        for(int i = 0; i < interval; i++) {

            int bones = (int)(random() * 3);

            switch (bones) {

                case 0 :
                    builder.append(getRandomUpperCaseLetter());
                    break;
                case 1 :
                    builder.append(getRandomLowerCaseLetter());
                    break;
                case 2 :
                    builder.append((int)(Math.random() * 9));
                    break;

            }

        }
        return builder.toString();
    }

    private static char getRandomUpperCaseLetter() {

        int k = (int) (random() * 25);

        switch (k) {
            case 0:
                return 'A';
            case 1:
                return 'B';
            case 2:
                return 'C';
            case 3:
                return 'D';
            case 4:
                return 'E';
            case 5:
                return 'F';
            case 6:
                return 'G';
            case 7:
                return 'H';
            case 8:
                return 'I';
            case 9:
                return 'J';
            case 10:
                return 'K';
            case 11:
                return 'L';
            case 12:
                return 'M';
            case 13:
                return 'N';
            case 14:
                return 'O';
            case 15:
                return 'P';
            case 16:
                return 'Q';
            case 17:
                return 'R';
            case 18:
                return 'S';
            case 19:
                return 'T';
            case 20:
                return 'U';
            case 21:
                return 'V';
            case 22:
                return 'W';
            case 23:
                return 'X';
            case 24:
                return 'Y';
            case 25:
                return 'Z';
            default:
                return 'Z';
        }

    }

    private static char getRandomLowerCaseLetter() {

        int k = (int) (random() * 25);

        switch (k) {
            case 0:
                return 'a';
            case 1:
                return 'b';
            case 2:
                return 'c';
            case 3:
                return 'd';
            case 4:
                return 'e';
            case 5:
                return 'f';
            case 6:
                return 'g';
            case 7:
                return 'h';
            case 8:
                return 'i';
            case 9:
                return 'j';
            case 10:
                return 'k';
            case 11:
                return 'l';
            case 12:
                return 'm';
            case 13:
                return 'n';
            case 14:
                return 'o';
            case 15:
                return 'p';
            case 16:
                return 'q';
            case 17:
                return 'r';
            case 18:
                return 's';
            case 19:
                return 't';
            case 20:
                return 'u';
            case 21:
                return 'v';
            case 22:
                return 'w';
            case 23:
                return 'x';
            case 24:
                return 'y';
            case 25:
                return 'z';
            default:
                return 'z';
        }

    }

    public static void main(String[] args) {

        System.out.println(generatePassword(PasswordDifficult.HARD));

    }
}




Java Source Code List

keepmysecretapp.app.com.keepmysecretapp.ApplicationTest.java
keepmysecretapp.app.com.keepmysecretapp.activities.MainActivity.java
keepmysecretapp.app.com.keepmysecretapp.activities.creation.CreateNewEntryActivity.java
keepmysecretapp.app.com.keepmysecretapp.activities.edit.EditEntryActivity.java
keepmysecretapp.app.com.keepmysecretapp.activities.presentation.EntryPresentActivity.java
keepmysecretapp.app.com.keepmysecretapp.adapters.DataEntryAdapter.java
keepmysecretapp.app.com.keepmysecretapp.adapters.GroupEntryAdapter.java
keepmysecretapp.app.com.keepmysecretapp.dao.Dao.java
keepmysecretapp.app.com.keepmysecretapp.dao.EntryDao.java
keepmysecretapp.app.com.keepmysecretapp.dao.GroupDao.java
keepmysecretapp.app.com.keepmysecretapp.db.DbContext.java
keepmysecretapp.app.com.keepmysecretapp.db.EntryType.java
keepmysecretapp.app.com.keepmysecretapp.fragments.creation.CreateDataEntryFragment.java
keepmysecretapp.app.com.keepmysecretapp.fragments.creation.CreateGroupFragment.java
keepmysecretapp.app.com.keepmysecretapp.fragments.dialogs.GeneratePasswordDialog.java
keepmysecretapp.app.com.keepmysecretapp.fragments.edit.EditDataFragment.java
keepmysecretapp.app.com.keepmysecretapp.fragments.edit.EditGroupFragment.java
keepmysecretapp.app.com.keepmysecretapp.fragments.other.NavigationDrawerFragment.java
keepmysecretapp.app.com.keepmysecretapp.fragments.other.SideLogic.java
keepmysecretapp.app.com.keepmysecretapp.fragments.presentation.EntryPresentFragment.java
keepmysecretapp.app.com.keepmysecretapp.fragments.presentation.TextKeeperFragment.java
keepmysecretapp.app.com.keepmysecretapp.other.Constants.java
keepmysecretapp.app.com.keepmysecretapp.other.Tools.java
keepmysecretapp.app.com.keepmysecretapp.tables.AuthTable.java
keepmysecretapp.app.com.keepmysecretapp.tables.DataTable.java
keepmysecretapp.app.com.keepmysecretapp.tables.GroupTable.java
keepmysecretapp.app.com.keepmysecretapp.tables.QueryTable.java
keepmysecretapp.app.com.keepmysecretapp.types.CopyTextButtonListener.java
keepmysecretapp.app.com.keepmysecretapp.types.GenerateButtonListener.java
keepmysecretapp.app.com.keepmysecretapp.types.ListEntry.java