Revision 038ac9a4 src/com/rackspacecloud/android/PasswordManager.java

b/src/com/rackspacecloud/android/PasswordManager.java
7 7
import android.content.SharedPreferences;
8 8

  
9 9
public class PasswordManager {
10
	
10

  
11 11
	private SharedPreferences settings;
12
	
13
	public PasswordManager(SharedPreferences sp){
12

  
13
	public PasswordManager(SharedPreferences sp) {
14 14
		settings = sp;
15 15
	}
16
	
16

  
17 17
	/*
18
	 * checks the parameter string against the stored
19
	 * password
18
	 * checks the parameter string against the stored password
20 19
	 */
21 20
	public boolean verifyEnteredPassword(String password) {
22 21
		return Arrays.toString(getHash(password)).equals(getStoredPassword());
23 22
	}
24
	
23

  
25 24
	/*
26
	 * return the hash of the password that is stored in
27
	 * shared preferences
25
	 * return the hash of the password that is stored in shared preferences
28 26
	 */
29
	private String getStoredPassword(){
27
	private String getStoredPassword() {
30 28
		return settings.getString(Preferences.PREF_KEY_PASSCODE_HASH, "");
31 29
	}
32
	
30

  
33 31
	/*
34
	 * turns off password requirement 
32
	 * turns off password requirement
35 33
	 */
36 34
	public void turnOffPassword() {
37 35
		SharedPreferences.Editor editor = settings.edit();
......
39 37
		editor.putBoolean(Preferences.PREF_KEY_PASSWORD_LOCK, false);
40 38
		editor.commit();
41 39
	}
42
	
40

  
43 41
	/*
44
	 * submits a password change into memory
45
	 * stores the sha-256 hash of the password
42
	 * submits a password change into memory stores the sha-256 hash of the
43
	 * password
46 44
	 */
47 45
	private void storeNewPassword(String hashedPassword) {
48 46
		SharedPreferences.Editor editor = settings.edit();
......
50 48
		editor.putBoolean(Preferences.PREF_KEY_PASSWORD_LOCK, true);
51 49
		editor.commit();
52 50
	}
53
	
51

  
54 52
	/*
55 53
	 * changes the password for
56 54
	 */
57 55
	public void changePassword(String password) {
58 56
		storeNewPassword(Arrays.toString(getHash(password)));
59 57
	}
60
	
58

  
61 59
	/*
62
	 * returns the sha-256 hash for a given
63
	 * string
60
	 * returns the sha-256 hash for a given string
64 61
	 */
65 62
	private byte[] getHash(String password) {
66 63
		MessageDigest m = null;
......
76 73
		}
77 74
		return m.digest();
78 75
	}
79
	
76

  
80 77
	/*
81 78
	 * returns true if their is a password requirement
82 79
	 */

Also available in: Unified diff