Search

Join this Blog for direct reference of any post into your inbox. To join just click on "Join this Site" under "Follower" then Login with your Email.*** DECLARATION: I Maintain this Blog for Helping Myself While at Work and Welcome any body Needing Help!!!.*** CAUTION: Using any of the script from this Blog may contain at Own Risk. These scripts May or May not have been Tested.***

Wednesday, 1 October 2014

How to Validate or Change User’s Password through Form

Through this post you are able to create a simple logon screen for the user to enter the software by providing username and password or facilitate the user to change his password through software at any time.

Design a simple form ‘TESTSEC_NEW’ with the field ‘USERNAM’ and ‘PASSWD’ along with ‘Exit’ button.
Write When_Button_Pressed Trigger on button ‘EXIT’
EXIT_FORM(NO_VALIDATE);
Write a Key_Next_Item Trigger on item ‘PASSWD’
:GLOBAL.USER   := :BLOCK1.USER_NAM;
:GLOBAL.PASSWD := :BLOCK1.PASSWD;
GET_SECURITY;   ---Get security is a procedure described below
CLEAR_RECORD;
CALL_FORM('.\gl\gl_tree.FMX');
Write ‘ON LOGON’ form Level Trigger.
logon('orafin','oracle'||'@'||'sadhan.world');
Where the ‘orafin’ is the database user or schema and ‘oracle’ is the password for that schema and ‘Sadhan.world’ is the connect string for the database.
Write GET_SECURITY procedure in Program Unit.
PROCEDURE GET_SECURITY IS
  DUM       NUMBER(4);
  BRN       NUMBER(2);
  DUM_PASS  VARCHAR2(10);
  CURSOR SEC IS
      SELECT GROUP_ID,USER_BRANCH FROM USER_PROGRAM
            WHERE USER_NAME = :GLOBAL.USER   
            AND USER_PASSWORD = DUM_PASS;
BEGIN
  --DUM_PASS := --EYD_ENCYPHER(:GLOBAL.PASSWD);
  DUM_PASS := :GLOBAL.PASSWD;
  OPEN SEC;
  FETCH SEC INTO DUM,BRN;
  IF SEC%NOTFOUND THEN
      FOR i in 1..5 LOOP
            BELL;
            SYNCHRONIZE;
      END LOOP;
      GET_MESS(106);
      CLOSE SEC;
      RAISE FORM_TRIGGER_FAILURE;
  END IF;
  :GLOBAL.GROUP_ID := DUM;
  :GLOBAL.BRANCH   := BRN;
  CLOSE SEC;
  exception
      when form_trigger_failure then
           raise form_trigger_failure;
      when others then
           show_message(2,2);
           raise form_trigger_failure;       
END;
Similarly if you required you can write the procedure to Encrypt or Decrypt your password with ‘Eyd_Encypher’  or ‘Eyd_Decypher’ and facility to change or validate password by the users.
FUNCTION Eyd_Decypher( Cypher_T VARCHAR2 )RETURN VARCHAR2 IS
  Z   NUMBER;
  PLAIN_T VARCHAR2(10) := NULL;
  CURSOR GET_SEC IS
      SELECT SYS_NUMBER FROM GEN_SYSTEM
            WHERE SYS_MAJ = 111
            AND   SYS_MIN = 0;
BEGIN
  OPEN GET_SEC;
  FETCH GET_SEC INTO Z;
  IF GET_SEC%NOTFOUND THEN
      CLOSE GET_SEC;
      GET_MESS(274);
      RAISE FORM_TRIGGER_FAILURE;
  ELSE
      IF NVL(LENGTH(CYPHER_T), 0) > 10 THEN
            RETURN(NULL);
      END IF;    
      FOR I IN 1..NVL(LENGTH(CYPHER_T), 0) LOOP
            PLAIN_T := PLAIN_T || CHR( 256 - ASCII(SUBSTR(CYPHER_T,I,1)) - Z + I );
      END LOOP;
  END IF;
  CLOSE GET_SEC;
  RETURN(PLAIN_T);
END;
FUNCTION Eyd_Encypher( Plain_T VARCHAR2 )RETURN VARCHAR2 IS
  Z   NUMBER;
  CYPHER_T  VARCHAR2(10) := NULL;
  ASCII_T   NUMBER;
  CURSOR GET_SEC IS
      SELECT SYS_NUMBER FROM GEN_SYSTEM
            WHERE SYS_MAJ = 111
            AND   SYS_MIN = 0;
BEGIN
  OPEN GET_SEC;
  FETCH GET_SEC INTO Z;
  IF GET_SEC%NOTFOUND THEN
      CLOSE GET_SEC;
      GET_MESS(274);
      RAISE FORM_TRIGGER_FAILURE;
  ELSE
      IF NVL(LENGTH(PLAIN_T), 0) > 10 THEN
            RETURN(NULL);
      END IF;
      FOR I IN 1..NVL(LENGTH(PLAIN_T), 0) LOOP
            ASCII_T  := ASCII(SUBSTR(PLAIN_T,I,1));
            IF ASCII_T BETWEEN 48 AND 122 THEN
            CYPHER_T := CYPHER_T || CHR( 256 + ( - ASCII_T ) - Z + I );
            ELSE
                  RETURN(NULL);
            END IF;
      END LOOP;
  END IF;
  CLOSE GET_SEC;
  RETURN(CYPHER_T);
END;
Procedure to facilitate User’s to change his Password:
DECLARE
  DUM  VARCHAR2(10);
BEGIN
  IF :PASS1 != :PASS2 THEN
       GET_MESS(149); --‘password is not matching’ a database defined Message
       GO_ITEM('PASS1');
       RAISE FORM_TRIGGER_FAILURE;
  ELSE
       DUM := :PASS2;--ENCYPHER(:PASS2);
       IF DUM IS NULL THEN
              GET_MESS(32);  --message code not define
              RAISE FORM_TRIGGER_FAILURE;
       ELSE
              CHANGE_PASS(:PASS2);
       END IF;
  END IF;
  show_message(1,'Done');
  GO_ITEM('PASS1');
END;
Procedure to Validate Password Changed:
PROCEDURE CHANGE_PASS (PASSWD VARCHAR2) IS
  DUM_NO      NUMBER;
  CURSOR CHK_PASSWD IS
       SELECT COUNT(DISTINCT USER_PASSWORD) FROM USER_PROGRAM
       where  user_name = :GLOBAL.USER; 
--USER_PROGRAM is database table where user_name and password stored.
BEGIN
  OPEN CHK_PASSWD;
  FETCH CHK_PASSWD INTO DUM_NO;
  IF CHK_PASSWD%NOTFOUND THEN
       SHOW_message(1,'There Is an Error, Call I.T. Department !');
  ELSE
       UPDATE USER_PROGRAM SET USER_PASSWORD = PASSWD
       where  user_name = :global.user;
       :SYSTEM.MESSAGE_LEVEL := 25;
       COMMIT;
       :SYSTEM.MESSAGE_LEVEL := 00;
  END IF;
END;
Check the other post How to display the ‘LOGO’ or ‘COMP_NAME’ or ‘CUSTOM_ERROR_MESSAGE’ defined in database.

0 comments:

Post a Comment