編程生活

             :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            113 隨筆 :: 0 文章 :: 18 評(píng)論 :: 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 閱讀(440) 評(píng)論(0)  編輯  收藏
          主站蜘蛛池模板: 读书| 道孚县| 镇赉县| 天全县| 泰来县| 永丰县| 成安县| 锦州市| 柳河县| 开封市| 新干县| 嘉荫县| 沽源县| 隆化县| 东乡族自治县| 玉溪市| 平阴县| 原平市| 天祝| 泸定县| 承德市| 宜丰县| 侯马市| 彝良县| 肇东市| 玛多县| 永春县| 镇安县| 古交市| 聊城市| 万源市| 渭南市| 中超| 孝义市| 洪洞县| 河北省| 临猗县| 隆德县| 赤水市| 邵东县| 浦东新区|