編程生活

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            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 閱讀(440) 評論(0)  編輯  收藏
          主站蜘蛛池模板: 右玉县| 蓬溪县| 临安市| 武乡县| 毕节市| 昌江| 安福县| 湘潭县| 澄城县| 饶河县| 临猗县| 和田市| 武城县| 浦城县| 宁安市| 太保市| 仪陇县| 离岛区| 永春县| 新源县| 鹰潭市| 南雄市| 景谷| 繁峙县| 大同市| 丰县| 平阴县| 鹤庆县| 百色市| 崇州市| 北流市| 韶山市| 三明市| 泰兴市| 拉萨市| 淄博市| 高台县| 松江区| 仪征市| 镇安县| 登封市|