编程生活

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  113 随笔 :: 0 文章 :: 18 评论 :: 0 Trackbacks

http://www.scribd.com/doc/76413826/161/Managing-RDBMS-Authentication 

private String parsePassword(String passInStr)
  
{
    
if ((passInStr == null|| (passInStr.length() < 1)) {
      
if (this.allowPlaintext)
        
return passInStr;
      
throw new PasswordHashException(ProvidersLogger.getPlaintextPasswordUsageRejected());
    }


    
char[] passIn = passInStr.toCharArray();
    
if (passIn[0!= '{')
    
{
      
if (this.allowPlaintext)
        
return passInStr;
      
throw new PasswordHashException(ProvidersLogger.getUnableParseHashedPassword());
    }


    
int i = 1;
    
while ((i < passIn.length) && (passIn[i] != '}'))
      i
++;
    
if (i >= passIn.length)
    
{
      
if (this.allowPlaintext)
        
return passInStr;
      
throw new PasswordHashException(ProvidersLogger.getUnableParseHashedPassword());
    }


    String algorithm 
= new String(passIn, 1, i - 1);
    
int offset = i + 1;
    
try
    
{
      
this.hashAlg = getHashAlgorithm(algorithm);
    }
 catch (PasswordHashException e) {
      
if (this.allowPlaintext)
        
return passInStr;
      
throw e;
    }

    
if ((this.hashAlg == null|| (this.hashAlg.getB64Size() == -1)) {
      
this.hashAlg = null;
      
if (this.allowPlaintext)
        
return passInStr;
      
throw new PasswordHashException(ProvidersLogger.getUnableParseHashedPassword());
    }


    
int totalRemaining = passIn.length - offset;
    
int saltSize = totalRemaining - this.hashAlg.getB64Size();
    
if (saltSize < 0{
      
this.hashAlg = null;
      
if (this.allowPlaintext)
        
return passInStr;
      
throw new PasswordHashException(ProvidersLogger.getUnableParseHashedPassword());
    }


    
if (saltSize > 0{
      
this.salt = new String(passIn, offset, saltSize);
      offset 
+= saltSize;
    }


    
char[] encodedPwdHashFromDB = new char[passIn.length - offset];
    System.arraycopy(passIn, offset, encodedPwdHashFromDB, 
0, passIn.length - offset);
    
return new String(encodedPwdHashFromDB);
  }


 

posted on 2012-04-27 14:27 wilesun 阅读(426) 评论(0)  编辑  收藏