編程生活

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            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 閱讀(442) 評論(0)  編輯  收藏
          主站蜘蛛池模板: 衡东县| 岱山县| 商城县| 涪陵区| 永德县| 叙永县| 孟村| 宜丰县| 潜山县| 新化县| 韶关市| 若尔盖县| 民乐县| 曲麻莱县| 大港区| 怀仁县| 西城区| 西安市| 临高县| 闽侯县| 普兰店市| 延长县| 惠水县| 普宁市| 邹城市| 丹东市| 马关县| 桐乡市| 灵台县| 全椒县| 安塞县| 大同市| 临泉县| 湘潭市| 基隆市| 左云县| 长春市| 公主岭市| 辉南县| 舒兰市| 古交市|