11package io .codespoof .univpassm ;
22
3- import androidx . appcompat . app . AppCompatActivity ;
4-
3+ import android . content . Intent ;
4+ import android . content . SharedPreferences ;
55import android .database .Cursor ;
66import android .os .Bundle ;
77import android .text .InputType ;
1111import android .widget .SimpleCursorAdapter ;
1212import android .widget .Toast ;
1313
14- import java . security . NoSuchAlgorithmException ;
15- import java . security . SecureRandom ;
14+ import androidx . appcompat . app . AppCompatActivity ;
15+ import androidx . preference . PreferenceManager ;
1616
1717public class MainActivity extends AppCompatActivity {
1818
@@ -22,38 +22,7 @@ public class MainActivity extends AppCompatActivity {
2222
2323 final int [] to = new int [] {R .id .datetime , R .id .content };
2424
25- private String generatePassword () {
26- StringBuilder pool = new StringBuilder ();
27- String chars = "abcdefghijklmnopqrstuvwxyz" ;
28- String signs = ".,-_:#*+=!" ;
29- String numbers = "0123456789" ;
30- SecureRandom secureRandomGenerator ;
31- try {
32- secureRandomGenerator = SecureRandom .getInstance ("SHA1PRNG" );
33- } catch (NoSuchAlgorithmException e ) {
34- throw new RuntimeException (e );
35- }
36- int upper = 0 ;
37- for (int i = 0 ; i < 5 ; i ++) {
38- String c = chars .substring (secureRandomGenerator .nextInt (chars .length ())).substring (0 , 1 );
39- if (upper < 4 && secureRandomGenerator .nextBoolean ()) {
40- c = c .toUpperCase ();
41- upper ++;
42- }
43- pool .append (c );
44- }
45- pool .append (signs .charAt (secureRandomGenerator .nextInt (signs .length ())));
46- pool .append (numbers .charAt (secureRandomGenerator .nextInt (numbers .length ())));
47- pool .append (numbers .charAt (secureRandomGenerator .nextInt (numbers .length ())));
48-
49- StringBuilder ret = new StringBuilder ();
50- for (int i = 0 ; i < 8 ; i ++) {
51- int ind = secureRandomGenerator .nextInt (pool .length ());
52- ret .append (pool .charAt (ind ));
53- pool .deleteCharAt (ind );
54- }
55- return ret .toString ();
56- }
25+ PasswordGenerator generator ;
5726
5827 @ Override
5928 protected void onCreate (Bundle savedInstanceState ) {
@@ -75,16 +44,21 @@ protected void onCreate(Bundle savedInstanceState) {
7544
7645 listView .setAdapter (adapter );
7746
47+ SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences (getApplicationContext ());
48+
49+ generator = new PasswordGenerator (preferences .getBoolean ("pref_url_compat" , false ), Integer .parseInt (preferences .getString ("pref_level" , "10" )));
50+
7851 EditText editPassword = findViewById (R .id .editPassword );
7952 Button resetButton = findViewById (R .id .buttonReset );
8053 Button repairButton = findViewById (R .id .buttonRepair );
54+ Button settingsButton = findViewById (R .id .buttonSettings );
8155 resetButton .setOnClickListener (v -> {
8256 Cursor c = dbManager .fetch ();
8357 c .moveToFirst ();
8458 if (c .getCount () > 0 ) {
8559 String oldPass = c .getString (2 );
86- String newPass = generatePassword ();
87- ChangePasswordTask task = new ChangePasswordTask ("chrsal2 " , oldPass , newPass , "login.schulen-wetteraukreis.de" , getApplicationContext (), dbManager , adapter , editPassword , repairButton , resetButton );
60+ String newPass = generator . generatePassword ();
61+ ChangePasswordTask task = new ChangePasswordTask (preferences . getString ( "pref_username " , "" ), oldPass , newPass , preferences . getString ( "pref_server_address" , "" ) , getApplicationContext (), dbManager , adapter , editPassword , repairButton , resetButton );
8862 task .execute ();
8963 } else {
9064 Toast .makeText (getApplicationContext (), R .string .history_empty , Toast .LENGTH_LONG ).show ();
@@ -108,6 +82,9 @@ protected void onCreate(Bundle savedInstanceState) {
10882 editPassword .setInputType (InputType .TYPE_TEXT_VARIATION_PASSWORD );
10983 }
11084 });
85+ settingsButton .setOnClickListener (v -> startActivity (new Intent (this , SettingsActivity .class )));
86+ if (preferences .getString ("pref_username" , "" ).equals ("" ))
87+ startActivity (new Intent (this , SettingsActivity .class ));
11188 }
11289
11390 @ Override
0 commit comments