/magstudentportal/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/magstudentportal/trunk

« back to all changes in this revision

Viewing changes to src/main/java/common/Utils.java

  • Committer: Gustav Hartvigsson
  • Date: 2017-09-08 07:44:36 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20170908074436-bux0hjwx9knwj3tn
* made the @Inject work.
* Fixed the hash function

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
   * @return
24
24
   */
25
25
  static public String
26
 
    real_hash_func (String t, String s) {
27
 
      int a = t.getBytes()[0];
28
 
      int b = t.getBytes()[a%t.length()];
29
 
 
30
 
      StringBuilder sb = new StringBuilder ();
31
 
      sb.append (t).insert (b, s);
32
 
 
33
 
      SHA3.DigestSHA3 md = new SHA3.DigestSHA3 (2048);
34
 
      try {
35
 
        md.update (sb.toString().getBytes("UTF-8"));
36
 
      } catch (Exception e) {
37
 
       md.update (sb.toString().getBytes()); 
38
 
      }
39
 
      return Hex.toHexString (md.digest ());
 
26
  real_hash_func (String t, String s) {
 
27
    int a = t.getBytes()[0];
 
28
    int b = s.getBytes()[a % s.length()] % s.length ();
 
29
 
 
30
    StringBuilder sb = new StringBuilder ();
 
31
    sb.append (t).insert (b, s);
 
32
 
 
33
    SHA3.DigestSHA3 md = new SHA3.DigestSHA3 (512);
 
34
    try {
 
35
      md.update (sb.toString().getBytes("UTF-8"));
 
36
    } catch (Exception e) {
 
37
     md.update (sb.toString().getBytes());
40
38
    }
 
39
    return Hex.toHexString (md.digest ());
 
40
  }
41
41
 
42
42
  /**
43
43
   * Hash a text with a salt.
46
46
   * @return
47
47
   */
48
48
  static public String
49
 
    hash_func (String t) {
50
 
      return real_hash_func(t, common.Config.PW_SALT);
51
 
    }
 
49
  hash_func (String t) {
 
50
    return real_hash_func(t, common.Config.PW_SALT);
 
51
  }
52
52
 
53
53
 
54
54
}