Ignore:
Timestamp:
09/05/11 21:47:01 (9 months ago)
Author:
delmitz
Branch:
default
Convert:
svn:7c3792e6-d75b-4784-96a6-b298f655ee64/trunk@2736
Message:

fixed otp seed reset bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kraken-dom/src/main/java/org/krakenapps/dom/api/impl/AdminApiImpl.java

    r301 r302  
    1818import java.util.Date; 
    1919import java.util.List; 
     20import java.util.Random; 
    2021 
    2122import javax.persistence.EntityManager; 
     
    254255                        admin.setLoginLockCount(targetAdmin.getLoginLockCount()); 
    255256                        admin.setUseOtp(targetAdmin.isUseOtp()); 
    256                         admin.setOtpSeed(targetAdmin.getOtpSeed()); 
     257                        if (admin.isUseOtp()) { 
     258                                if (targetAdmin.getOtpSeed() != null) 
     259                                        admin.setOtpSeed(targetAdmin.getOtpSeed()); 
     260                                else if (admin.getOtpSeed() == null) 
     261                                        admin.setOtpSeed(createOtpSeed()); 
     262                        } else 
     263                                admin.setOtpSeed(null); 
    257264 
    258265                        if (!admin.isEnabled() && targetAdmin.isEnabled()) 
     
    268275                } 
    269276        } 
     277 
     278        private static final char[] chars = new char[62]; 
     279        static { 
     280                int i = 0; 
     281                char c = 'a'; 
     282                for (; i < 26; i++) 
     283                        chars[i] = c++; 
     284                c = 'A'; 
     285                for (; i < 52; i++) 
     286                        chars[i] = c++; 
     287                c = '0'; 
     288                for (; i < 62; i++) 
     289                        chars[i] = c++; 
     290        } 
     291 
     292        private String createOtpSeed() { 
     293                Random random = new Random(); 
     294                StringBuilder sb = new StringBuilder(); 
     295                for (int i = 0; i < 10; i++) 
     296                        sb.append(chars[random.nextInt(62)]); 
     297                return sb.toString(); 
     298        } 
    270299} 
Note: See TracChangeset for help on using the changeset viewer.