Skip to content

Commit 1a9ddaf

Browse files
authored
Merge pull request #1 from amansinghrajpoot/patch-1
Added Exception incorrect_password and refactored code.
2 parents 178d7a6 + 8c43ece commit 1a9ddaf

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Library.sql

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,24 @@ INSERT INTO Rent VALUES (155, 'V1CH16', '29-04-2018', '29-05-2018');
214214
CREATE OR REPLACE PROCEDURE loginCustomer_library(user IN VARCHAR2, pass IN VARCHAR2)
215215
IS
216216
passAux customer.password%TYPE;
217+
incorrect_password EXCEPTION;
217218
BEGIN
219+
220+
218221
SELECT password INTO passAux
219222
FROM customer
220223
WHERE username LIKE user;
221224

222225
IF passAux LIKE pass THEN
223226
DBMS_OUTPUT.PUT_LINE('User ' || user || ' loging succesfull');
224227
ELSE
225-
DBMS_OUTPUT.PUT_LINE('Password incorrect');
228+
RAISE incorrect_password;
226229
END IF;
227230

228-
EXCEPTION WHEN no_data_found THEN
229-
DBMS_OUTPUT.PUT_LINE('User incorrect');
231+
EXCEPTION
232+
WHEN no_data_found OR incorrect_password THEN
233+
DBMS_OUTPUT.PUT_LINE('Incorrect username or password');
234+
230235
END;
231236

232237
SET SERVEROUTPUT ON;
@@ -244,6 +249,7 @@ END;
244249
CREATE OR REPLACE PROCEDURE loginEmployee_library(user IN VARCHAR2, pass IN VARCHAR2)
245250
IS
246251
passAux employee.password%TYPE;
252+
incorrect_password EXCEPTION;
247253
BEGIN
248254
SELECT password INTO passAux
249255
FROM employee
@@ -252,11 +258,12 @@ BEGIN
252258
IF passAux LIKE pass THEN
253259
DBMS_OUTPUT.PUT_LINE('User ' || user || ' loging succesfull');
254260
ELSE
255-
DBMS_OUTPUT.PUT_LINE('Password incorrect');
261+
RAISE incorrect_password;
256262
END IF;
257263

258-
EXCEPTION WHEN no_data_found THEN
259-
DBMS_OUTPUT.PUT_LINE('User incorrect');
264+
EXCEPTION
265+
WHEN no_data_found OR incorrect_password THEN
266+
DBMS_OUTPUT.PUT_LINE('Incorrect username or password');
260267
END;
261268

262269
SET SERVEROUTPUT ON;

0 commit comments

Comments
 (0)