]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/util/PasswordHash.java
Format code according do BenBE's formatter.
[gigi.git] / src / org / cacert / gigi / util / PasswordHash.java
index 71f7547979c9ae06c5a83ca2530fd0d9ca4763be..aaff22686389c974b7b856e9914f11a91d104146 100644 (file)
@@ -4,34 +4,35 @@ import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 
 public class PasswordHash {
-       public static boolean verifyHash(String password, String hash) {
-               String newhash = sha1(password);
-               boolean match = true;
-               if (newhash.length() != hash.length()) {
-                       match = false;
-               }
-               for (int i = 0; i < newhash.length(); i++) {
-                       match &= newhash.charAt(i) == hash.charAt(i);
-               }
-               return match;
-       }
 
-       private static String sha1(String password) {
-               try {
-                       MessageDigest md = MessageDigest.getInstance("SHA1");
-                       byte[] digest = md.digest(password.getBytes());
-                       StringBuffer res = new StringBuffer(digest.length * 2);
-                       for (int i = 0; i < digest.length; i++) {
-                               res.append(Integer.toHexString((digest[i] & 0xF0) >> 4));
-                               res.append(Integer.toHexString(digest[i] & 0xF));
-                       }
-                       return res.toString();
-               } catch (NoSuchAlgorithmException e) {
-                       throw new Error(e);
-               }
-       }
+    public static boolean verifyHash(String password, String hash) {
+        String newhash = sha1(password);
+        boolean match = true;
+        if (newhash.length() != hash.length()) {
+            match = false;
+        }
+        for (int i = 0; i < newhash.length(); i++) {
+            match &= newhash.charAt(i) == hash.charAt(i);
+        }
+        return match;
+    }
 
-       public static String hash(String password) {
-               return sha1(password);
-       }
+    private static String sha1(String password) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("SHA1");
+            byte[] digest = md.digest(password.getBytes());
+            StringBuffer res = new StringBuffer(digest.length * 2);
+            for (int i = 0; i < digest.length; i++) {
+                res.append(Integer.toHexString((digest[i] & 0xF0) >> 4));
+                res.append(Integer.toHexString(digest[i] & 0xF));
+            }
+            return res.toString();
+        } catch (NoSuchAlgorithmException e) {
+            throw new Error(e);
+        }
+    }
+
+    public static String hash(String password) {
+        return sha1(password);
+    }
 }