Develop and Download Open Source Software

Browse CVS Repository

Diff of /gikonavigoeson/gikonavi/Trip.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.4 by h677, Sat Aug 5 04:59:42 2006 UTC revision 1.5 by h677, Sat Jun 20 15:37:28 2009 UTC
# Line 9  unit Trip; Line 9  unit Trip;
9  }  }
10  interface  interface
11    
12    uses
13        SHA1Unit, UBase64, SysUtils;
14    
15  type  type
16          CryptBlock = record          CryptBlock = record
17                  b_data : array [0..63] of char;                  b_data : array [0..63] of char;
# Line 417  begin Line 420  begin
420    
421  end;  end;
422    
423    procedure get_pw_salt(
424        const pw : PChar;
425        var convpw : String;
426        const salt : PChar
427    );
428    var
429        i : integer;
430    begin
431        // ^([0-9A-Fa-f]{16})([./0-9A-Za-z]{0,2})$
432        if (Length(pw) >= 17) or (Length(pw) <= 19) then begin
433            // キー部分
434            for  i := 0 to 7 do begin
435                if (Pos(pw[2*i + 0 + 1], '0123456789abcdefABCDEF') > 0) and
436                    (Pos(pw[2*i + 1 + 1], '0123456789abcdefABCDEF') > 0) then begin
437                    convpw := convpw +
438                        Char(StrToInt( pw[2*i + 0 + 1] ) shl 4 + StrToInt( pw[2*i + 1 + 1] ));
439                end else begin
440                    convpw := '';
441                    Break;
442                end;
443            end;
444    
445            if (Length(convpw) = 8) then begin
446                if (Length(pw) = 19) then begin
447                    if (Pos(pw[17], './0123456789abcdefABCDEF') > 0) and
448                        (Pos(pw[18], './0123456789abcdefABCDEF') > 0) then begin
449                        salt[ 0 ] := pw[17];
450                        salt[ 1 ] := pw[18];
451                        salt[ 2 ] := #0;
452                    end else begin
453                        convpw := '';
454                    end;
455                end else if (Length(pw) = 18) then begin
456                    if (Pos(pw[17], './0123456789abcdefABCDEF') > 0) then begin
457                        salt[ 0 ] := pw[17];
458                        salt[ 1 ] := '.';
459                        salt[ 2 ] := #0;
460                    end else begin
461                        convpw := '';
462                    end;
463                end else begin
464                    salt[ 0 ] := '.';
465                    salt[ 1 ] := '.';
466                    salt[ 2 ] := #0;
467                end;
468            end;
469        end;
470    end;
471    
472  function get_2ch_trip(  function get_2ch_trip(
473          const pw : PChar          const pw : PChar
474  ) : string;  ) : string;
475  var  var
476          s : CryptData;          s : CryptData;
477          salt : array [0..2] of char;          salt : array [0..2] of char;
478        digest : TSHA1Digest;
479        convpw : String;
480  begin  begin
481        Result := '';
482          if pw[ 0 ] = #0 then          if pw[ 0 ] = #0 then
483          begin          begin
                 Result := '';  
484                  Exit;                  Exit;
485          end;          end;
486        // 11桁までは旧方式
487      get_salt( pw, salt );      if (Length(pw) <= 11) then begin
488            get_salt( pw, salt );
489            Result := Copy( crypt_r( pw, salt, s ), 4, 100 );
490          Result := Copy( crypt_r( pw, salt, s ), 4, 100 );      end else begin
491            // 新方式トリップ
492            if pw[ 0 ] = '$' then begin
493                // 将来の拡張用
494                Result := '???';
495            end else begin
496                convpw := '';
497                // 生キー方式
498                if pw[ 0 ] = '#' then begin
499                    get_pw_salt(pw, convpw, salt);
500                end;
501                if Length(convpw) = 8 then begin
502                    Result := Copy( crypt_r( PChar(convpw), salt, s ), 4, 100 );
503                end else begin
504                    // 新方式
505                    StringHashSHA1(digest, pw);
506                    Result := Copy(HogeBase64Encode(digest), 0, 12);
507                end;
508            end;
509        end;
510  end;  end;
511    
512  procedure get_salt(  procedure get_salt(

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26