OSDN Git Service

IE9以外でも除算エラーを無効にしていたのを修正
[gikonavigoeson/gikonavi.git] / Trip.pas
index 1c2a78a..262268f 100644 (file)
--- a/Trip.pas
+++ b/Trip.pas
@@ -10,7 +10,7 @@ unit Trip;
 interface
 
 uses
-    SHA1Unit, UBase64, SysUtils;
+    SHA1Unit, UBase64, SysUtils, MojuUtils;
 
 type
        CryptBlock = record
@@ -424,18 +424,18 @@ procedure get_pw_salt(
     const pw : PChar;
     var convpw : String;
     const salt : PChar
-);
+) ;
 var
     i : integer;
 begin
     // ^([0-9A-Fa-f]{16})([./0-9A-Za-z]{0,2})$
-    if (Length(pw) >= 17) or (Length(pw) <= 19) then begin
+    if (Length(pw) >= 17) and (Length(pw) <= 19) then begin
         // \83L\81[\95\94\95ª
         for  i := 0 to 7 do begin
             if (Pos(pw[2*i + 0 + 1], '0123456789abcdefABCDEF') > 0) and
                 (Pos(pw[2*i + 1 + 1], '0123456789abcdefABCDEF') > 0) then begin
                 convpw := convpw +
-                    Char(StrToInt( pw[2*i + 0 + 1] ) shl 4 + StrToInt( pw[2*i + 1 + 1] ));
+                    Char(StrToInt( 'x' + pw[2*i + 0 + 1] ) shl 4 + StrToInt( 'x'  + pw[2*i + 1 + 1] ));
             end else begin
                 convpw := '';
                 Break;
@@ -494,16 +494,23 @@ begin
             Result := '???';
         end else begin
             convpw := '';
-            // \90\83L\81[\95û\8e®
-            if pw[ 0 ] = '#' then begin
+            if (pw[ 0 ] = '#') and (Length(pw) >= 20) then begin
+                // \8f«\97\88\82Ì\8ag\92£\97p
+                Result := '???';
+            end else if pw[ 0 ] = '#' then begin
+                // \90\83L\81[\95û\8e®
                 get_pw_salt(pw, convpw, salt);
-            end;
-            if Length(convpw) = 8 then begin
-                Result := Copy( crypt_r( PChar(convpw), salt, s ), 4, 100 );
+                if Length(convpw) = 0 then begin
+                    // \90\83L\81[\95û\8e®\83G\83\89\81[
+                    Result := '???';
+                end else if Length(convpw) = 8 then begin
+                    Result := Copy( crypt_r( PChar(convpw), salt, s ), 4, 100 );
+                end
             end else begin
                 // \90V\95û\8e®
                 StringHashSHA1(digest, pw);
                 Result := Copy(HogeBase64Encode(digest), 0, 12);
+                Result := MojuUtils.CustomStringReplace(Result, '+', '.');
             end;
         end;
     end;