Wednesday, September 19, 2012

Create a login screen in oracle forms builder 10g

First :

Create table with two columns (username , password )

CREATE TABLE PASSWORD
(USER_ID    NUMBER(3)  CONSTRAINT  PASSWORD_USER_ID_PK PRIMARY KEY,
 PASSWORD VARCHAR2(20) NOT NULL);
INSERT INTO PASSWORD (USER_ID,PASSWORD)
VALUES (1,100);
INSERT INTO PASSWORD (USER_ID,PASSWORD)
VALUES (2,200);

Second:

Create Forms Look Like the Following :

Third :

You have two way to check Username, password :

Using Trigger in When_button_presses

BEGIN
SELECT USER_ID
INTO   :GLOBAL.USER_ID
FROM   PASSWORD
WHERE  USER_ID = :LOGIN.TI_USER_ID
AND    PASSWORD= :LOGIN.TI_PASSWORD;
GO_BLOCK('PASSWORD');
EXCEPTION
WHEN NO_DATA_FOUND THEN
:GLOBAL.COUNT := :GLOBAL.COUNT + 1;
IF :GLOBAL.COUNT = 1 THEN
MESSAGE('wrong');
MESSAGE('wrong');
ELSIF
:GLOBAL.COUNT = 2 THEN
MESSAGE('wrong');
MESSAGE('wrong');
ELSIF
:GLOBAL.COUNT = 3 THEN
EXIT_FORM;
END IF;
END;
there's million way to do this . this is the easy one


you Can Create procedure inside Program_unit Name it Vaildation_pass.





But Inside When_button_pressed Write procedure name .

 

 Vaildation_pass
PROCEDURE VALIDATION_PASS IS
BEGIN
SELECT USER_ID
INTO   :GLOBAL.USER_ID
FROM   PASSWORD
WHERE  USER_ID = :LOGIN.TI_USER_ID
AND    PASSWORD= :LOGIN.TI_PASSWORD;
GO_BLOCK('PASSWORD');
EXCEPTION
WHEN NO_DATA_FOUND THEN
:GLOBAL.COUNT := :GLOBAL.COUNT + 1;
IF :GLOBAL.COUNT = 1 THEN
MESSAGE(wrong');
MESSAGE(wrong');

ELSIF
:GLOBAL.COUNT = 2 THEN
MESSAGE(wrong');
MESSAGE(wrong');
ELSIF
:GLOBAL.COUNT = 3 THEN
EXIT_FORM;
END IF;
END;

Notice that above code contain global_variable So We need to add Trigger (form_level)/When_new_forms_instance.

Inside this trigger add  :GLOBAL.COUNT = 0


Subject Written by Arefa in Arabic Review it here

Thank You
Osama Mustafa

15 comments:

  1. this is very nice but ...now i want to change a user name and password , or create another user what should be done

    ReplyDelete
  2. thats very good for single user now i want to create another user or change the password what should be done

    ReplyDelete
  3. i don' think login screen will allow for more than one user to log in ...
    its always for single user

    this or please clarify your point

    ReplyDelete
  4. It isnt working.....its giving an error bad bind variable

    ReplyDelete
    Replies
    1. hi Frankie
      Post error like you see it , and when you press double click on the error it will automatically direct you to the error.

      Delete
  5. Asalamu Alkaikum bhaai
    alhamduillah
    its working fine

    i use your query with my password table

    thank u

    i want to friend ship with u bhaai
    my email is basharmits@gmail.com

    ReplyDelete
  6. Your welcome
    You can check my social media i posted on my blog :)

    ReplyDelete
  7. kindly elaborate this more.

    Notice that above code contain global_variable So We need to add Trigger (form_level)/When_new_forms_instance.

    Inside this trigger add :GLOBAL.COUNT = 0

    and about the logout code? :)

    ReplyDelete
    Replies
    1. i have an error it says

      "Error 49 line 5 column 19
      bad bind variable 'LOGIN.TI_USER_ID'

      Error 49 line 6 column 19
      bad bind variable'LOGIN.TI_PASSWORD'

      panu to ayusin ate?

      Delete
  8. it is not working, it always gives me the same error: "wrong" :(((((

    ReplyDelete
  9. always runs the exception even if the condition is correct

    ReplyDelete
  10. I'm new to Oracle Forms 10g.
    When I create a data block based on a table using Data Block Wizard, the block's Query Data Source Columns property is automatically populated with column definition entries corresponding to the columns of the base table.
    I tried making changes to these entries, for example by changing the data types to wrong data types or even deleting them, and I found that those changes had no effect on the block at all. The form was still working as I wanted.
    Please explain what is exactly the role of the block's Query Data Source Columns property.

    Thank you very much.

    p.s: The F1 key help says "The Query Data Source Columns property is valid only when the Query Data Source Type property is set to Table, Sub-query, or Procedure". So, please explain in each context of Query Data Source Type.

    ReplyDelete
  11. i have an error it says

    "Error 49 line 5 column 19
    bad bind variable 'LOGIN.TI_USER_ID'

    Error 49 line 6 column 19
    bad bind variable'LOGIN.TI_PASSWORD'


    can you help me sir?

    ReplyDelete
  12. declare
    uname login.username%type;
    pass login.password%type;

    cursor mycur is select username,password from login;
    begin
    open mycur;
    loop
    fetch mycur into uname, pass;
    if :username=uname and :password= pass
    then
    message('valid user');
    exit when mycur%found;
    elsif mycur%notfound
    then
    message ('invalid user');
    exit when mycur%notfound;
    end if;
    end loop;
    close mycur;
    end;
    error login.username must be declared

    ReplyDelete