# Database Discussions > Oracle >  How to create a login form (Oracle9i)

## meLady

*Hello,*

I have a table called users, and it has two fields "username" & "password".

I have created a form called "UserLogin.frm", and it has as the following:

1-  txtUsername
2-  txtPassword
3-  btnEnter

the idea is that the user must enter his/her username & password in the mentioned textboxes respectively.  Then s/he will press the Enter Button.

The system will varify the input by matching the data in the users table.  If it wrong, the error message will appear.  If it correct, the required form will be displayed.

So, this process is very new to me ... and I would like to learn it and I would be more appreciated by having your kindly assistance.

----------


## meLady

can anyone help me!!??? :EEK!:

----------


## meLady

Anyone!!!!!  :EEK!:

----------


## spoons

<?php
	if($_SERVER['REQUEST_METHOD'] == "POST"){
		$txt_user_name = $_POST['txtUsername'];
		$txt_password = $_POST['txtPassword'];

		$connection = oci_connect("dbUsername", "dbPassword");

		$Sql ="SELECT username, 
					  password
				 FROM tblName
				WHERE username = $txt_user_name";

		$statement = oci_parse ($connection, $Sql);
		oci_execute ($statement);

	while ($row = oci_fetch_array ($statement, OCI_BOTH)) {
		if( ($row['USERNAME'] == $txt_user_name) && ($row['PASSWORD'] == $txt_password) )
			echo "Login successful";
		else
			echo "Error login!";
	}
?>

juss write the above mentioned code in top of your form,
i assume that u have the correct username and password to your db.

Enjoy Coding!
Cheers!

----------


## meLady

*Hello Spoons,*

Thanks for the coding ... I will try to excute the code that you have provided me ... if there is something that I don't understand .. then I will send my questions here ...  :Big Grin:  

So, please be with me  :Stick Out Tongue:  because it is my first time that I am going to use the login process in the Oracle.

Again thanks for the coding  :Stick Out Tongue:

----------


## stecal

What are you using to create the form? Why is your form using frm as a file extension instead of fmb?

----------


## spoons

hellow meLady,

i guess the code i sent is working.
for timebeing it's okie, but it's not the rt. practice to code.

Instead if i were to make a login frm i would use some kind of hierarchy among folders and file such as.

configure(folder)
-->dbConnect.php(// this file includes connection string)

class(folder)
-->tblName.php(// all the DML activity related to particular table)

project/module_name(folder. eg admin for admin panel)
-->login_form.php (// Your frontend file. All you have to do is include the dbConnect.php and tblName.php file in here and juss call the function that's in class/tblName.php

----------


## spoons

Hello meLady,

i guess the code i sent is working.
for timebeing it's okie, but it's not the rt. practice to code.

Instead if i were to make a login frm i would use some kind of hierarchy among folders and file such as.

configure(folder)
-->dbConnect.php(// this file includes connection string)

class(folder)
-->tblName.php(// all the DML activity related to particular table)

project/module_name(folder. eg admin for admin panel)
-->login_form.php (// Your frontend file. All you have to do is include the dbConnect.php and tblName.php file in here and juss call the function that's in class/tblName.php

Cheers!

----------


## meLady

*Hello Spoons,*

How are you?  Thanks for the coding it is pleasure to have a nice help from you (^_^).

Actually, I will try to use what you gave me ... Because I am a new learner ... I have just learnt the Oracle form developer basic for 6 months ... but I have a good understanding in SQL language ... but to use it in form developer I guess I need some time to learn it (^_^)

Thanks for the help

Note:   But I haven't used a PHP in oracle9i form developer before ... why we have to use it ... can we avoid it (^_^) because I am not sure yet that I am able to learn some tough coding  :Big Grin:  

I am waiting for your kindly reply  :Stick Out Tongue:

----------


## Anu1

Hi,

Step1: 
Craete testitem ITEM1 for username.
Craete testitem ITEM2 for password.
create button item BTN_ENTER for "enter" button.


Step 2:
Write "when button pressed" trigger for the "enter" button..
IF :<BLOCK NAME>.ITEM1 ="USER" THEN
  IF :<BLOCK NAME>.ITEM2 ="PASSWORD" THEN
   NEW_FORM("FORM_NAME");
  ELSE
    MESSAGE('PASSWORD  WRONG');
  END IF;
ELSE
MESSAGE('USERNAME  WRONG');
END IF;

----------


## spoons

Hello meLady,

1. verify for null username (username cannot be null)
2. verify for null password (password cannot be null)
3. If we get a username and password, authenticate it wih PLSQL like SELECT password into vresult
     from users where username=txtUsername;
IF(txtPassword = vresult) THEN
  /*You are in*/
ELSE
  /*You are not in*/
END IF;
4. This is all meLady. Yes, you can have ecrypted password stored in table 
and encrypt the password given by user while verifying the password that 
user enters. For this, the function used while encrypting the password 
given for new user should be same as the decrypting function while 
verifying at Login.

Sorry, for late respose as i was out of town, but bfr leaving i sent this solution which somehow couldn't submitted.

Enjoy coding.

----------


## sundarbs

Hi Melady,

The responce by Anu1 gives the appropriate solution as you said you are using Oracle Developer suite 9i(D2K). You need to use the decrypt/encrypt function in caase if you are storing the password in encrypted form.

Thanks,

----------

