RPGIV @ Work

A unique site for RPG and System i Lovers

Welcome!

Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

Check password field with Hash Key (passwords are stored in a DB2 file in SHA1 format) Print E-mail
User Rating: / 0
PoorBest 

Written by Chamara Withanachchi   
      * --------------------------------------------------------------- *
      *         Application      :  Utility                             *
      *         Program Id       :  SHAPWD                              *
      *         Title            :  Login to user sub system            *
      *         Description      :  This program will check and login   *
      *                             to the system, passwords are stored *
      *                             in table in ASCII format and they   *
      *                             were hashed by SHA1 algo.           *
      *                                                                 *
      *        Author            : Chamara Withanachchi                 *
      *        Date              : 2008//05/04                          *
      *                                                                 *
      * --------------------------------------------------------------- *
      * MODIFICATIONS                                                   *
      * --------------------------------------------------------------- *
      * --------------------------------------------------------------- *
     H DFTACTGRP(*NO) ACTGRP('CHAMARA') BNDDIR('QC2LE')
     H OPTION(*NODEBUGIO)

      * --------------------------------------------------------------- *
      * File specifications
      * --------------------------------------------------------------- *

      * IC User file .....
     FUSRTL01   IF   E           K DISK    ReName(ICTUSR1 : UserRec)

      * --------------------------------------------------------------- *
      * Variable specifications
      * --------------------------------------------------------------- *
     D Qc3CalculateHash...
     D                 PR                  ExtProc('Qc3CalculateHash')
     D   InputData                     *   value
     D   InputDataLen                10i 0 const
     D   InputDataFmt                 8a   const
     D   AlgDesc                     16a   const
     D   AlgFmt                       8a   const
     D   CryptoSP                     1a   const
     D   CryptoDev                    1a   const options(*omit)
     D   Hash                        64a   options(*varsize:*omit)
     D   ErrorCode                32767a   options(*varsize)

     D ALGD0500_t      ds                  qualified
     D                                     based(Template)
     D   HashAlg                     10i 0

     D QDCXLATE        PR                  ExtPgm('QDCXLATE')
     D   len                          5p 0 const
     D   data                     32702a   options(*varsize)
     D   table                       10a   const

     D cvthc           PR                  ExtProc('cvthc')
     D   target                   65534A   options(*varsize)
     D   src_bits                 32767A   options(*varsize) const
     D   tgt_length                  10I 0 value

     D ErrorNull       ds                  qualified
     D    BytesProv                  10i 0 inz(0)
     D    BytesAvail                 10i 0 inz(0)

     D HASH_MD5        c                   1
     D HASH_SHA1       c                   2
     D HASH_SHA256     c                   3
     D HASH_SHA384     c                   4
     D HASH_SHA512     c                   5

     D ClrPwdData      s             80A
     D len             s             10i 0
     D alg             ds                  likeds(ALGD0500_t)
     D binhash         s             20a
     D hexhash         s             40a

     D CurPwd          s             10a

     D ICSHAPWDM       PR                  EXTPGM('ICSHAPWDM')
     D  UserId                       15A
     D  Pwd                          10A

     D ICSHAPWDM       PI
     D  UserId                       15A
     D  Pwd                          10A

      * --------------------------------------------------------------- *
      * Main Line
      * --------------------------------------------------------------- *
      /free

         setll UserId UserRec;
         reade UserId UserRec;
         if  not %EOF(USRTL01);

            CurPwd = Pwd ;

               if CurPwd <> *blanks;
                  ClrPwdData = CurPwd;

                  len = %len(%trimr(ClrPwdData));
                  alg.HashAlg = HASH_SHA1;

                  QDCXLATE(len: ClrPwdData: 'QTCPASC');
                  Qc3CalculateHash( %addr(ClrPwdData)
                                  : len
                                  : 'DATA0100'
                                  : alg
                                  : 'ALGD0500'
                                  : '0'
                                  : *OMIT
                                  : binhash
                                  : ErrorNull );

                  cvthc( hexhash: binhash: %len(binhash)*2);

                  if hexhash = SHAPS1;
                     dsply 'Login OK';
                  endif;

               endif;

         endif;

         *inlr = *on;

      /end-free      
User Comments

Please login or register to add comments

<Previous   Next>