Validate user for 3 login entrance attempts

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
Post Reply
reenanneliaas
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 12
Joined: Tue, 02 Sep 2014 11:01 am

aí GALERA, I have a small and simple difficulty validating the user.

I want to try to make a script that the user has 3 attempts to enter your login and password. And I have to do this with repeating lace or a: While.
But I am having difficulty asking the user after it entered wrong with two more chances. And the script I did only do one, the purpose of this script, is to create a simple script with while based on my database.

Below is the script:

Select all

create table Administrador( 
ID_Administrador number(4) primary key not null, 
Nome_Administrador varchar(30), 
Email_Administrador varchar(100), 
Senha_Admin varchar(16) not null); 
 
INSERT INTO Administrador VALUES (1,'Felipe Silva','felipe@xama.com','felipe123'); 
 
DECLARE 
v_idadmin    administrador.id_administrador%TYPE:=1; 
v_senha       administrador.senha_admin%TYPE; 
a                 number (2):=1; 
 
    BEGIN 
 
        SELECT ID_Administrador,Senha_Admin 
        INTO v_idadmin,v_senha 
        FROM Administrador; 
 
            IF v_idadmin = :P_ID and v_senha = :P_SENHA THEN 
            dbms_output.put_line ('Seja bem vindo'); 
            ELSE 
                WHILE a = 1 
                        LOOP 
                           FOR i in i <3   
                              LOOP                                                        
                                 dbms_output.put_line ('Senha do usuário não confere'); 
                             
                               END LOOP; 
                    a := a+1;  
                        dbms_output.put_line ('entre em contado com o Administrador do Sistema '); 
                    END LOOP; 
    
            END IF; 
    END;
Last edited by stcoutinho on Tue, 02 Sep 2014 3:57 pm, edited 1 time in total.
Reason: Obs: Editado para facilitar a visualizacao do codigo PL/SQL
User avatar
dr_gori
Moderador
Moderador
Posts: 5026
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

But will you use what to read from the keyboard the password?
The way you did, he's looking for the table password. That is, it is certain that the password is correct.

explains better for us.
reenanneliaas
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 12
Joined: Tue, 02 Sep 2014 11:01 am

As you can check I used a variable BIND to enter data from the keyboard.
These:

Select all

:P_ID e :P_SENHA 
At the time of validating if the user is or not existing, okay,
I just wanted to know how I do for the User to enter your login again if it first missed.

And so the script allows the user to try only 3 times.
User avatar
dr_gori
Moderador
Moderador
Posts: 5026
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Do you run this on SQL * Plus?
I think there's no way to get a variable BIND Denovo.

There is the Accept command, but I think it does not suit this case.

Select all

ACCEPT senha CHAR PROMPT 'Digite sua senha:  ' HIDE
(because it is a SQL * Plus and not PLSQL command).
reenanneliaas
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 12
Joined: Tue, 02 Sep 2014 11:01 am

I run on toad, I think better. rs
because it's expensive, I think I'll have to study another part of my bank to do this loop.
I have already tried several forms, put an IF inside the for,
declare a variable to only capture the input.
But this variable that I declare, asks me to declare the input data of the keyboard, so it does not work, the way is to study another method.

Thanks for the interest and help. : D
User avatar
dr_gori
Moderador
Moderador
Posts: 5026
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

So, I think "in real life" this your case is very difficult to happen, because you're running on toad, and no one will do it. (If you are using toad, then you are a programmer, you do not need a password icon control).

I would make a function that validates password, which returns true or false.
Within this procedure, it tests if it hit.
* If you missed, save the date on the table you missed and the amount of times you missed. (in case 1).
* If you missed again, add 1 in the amount of times the wrong.
* If it goes from 3 times, then he will have to wait, I know it, (one hour) to try again. (Test this by the date of the first error).
* If it hit, clean the amount of times and date.

Oh yes, you can use this anywhere and Function that will do all the service.
reenanneliaas
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 12
Joined: Tue, 02 Sep 2014 11:01 am

I'm starting now to use pl sql,
this loop scheme, I have to do for college, because if it were to do a function I think it would be easier for sure.
For all the time the user erred the procedure performed false, and later counted on the table as you even said, thus having two more attempts.

I know I'm trying to do it the most complicated way. Hahahaha
marlonpasquali
Rank: DBA Pleno
Rank: DBA Pleno
Posts: 248
Joined: Fri, 06 Feb 2009 3:02 pm
Location: ERECHIM - RS

Test this:

Select all

DECLARE 
v_idadmin    administrador.id_administrador%TYPE:=1; 
v_senha       administrador.senha_admin%TYPE; 
a                 number (2):=0; 
 
    BEGIN 
 
        SELECT ID_Administrador,Senha_Admin 
        INTO v_idadmin,v_senha 
        FROM Administrador; 
 
            IF v_idadmin = :P_ID and v_senha = :P_SENHA THEN 
               dbms_output.put_line ('Seja bem vindo'); 
            ELSE 
                WHILE a <= 3 LOOP 
                               IF v_idadmin = :P_ID and v_senha = :P_SENHA THEN                 
                                 dbms_output.put_line ('Seja bem vindo'); 
                                 EXIT; 
                               ELSE   
                                 dbms_output.put_line ('Senha do usuário não confere'); 
                                 dbms_output.put_line ('entre em contado com o Administrador do Sistema '); 
                                 a := a+1;                                  
                               END IF;   
                END LOOP; 
    
            END IF; 
    END;
reenanneliaas
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 12
Joined: Tue, 02 Sep 2014 11:01 am

Thanks for the suggestion.
More I'vê realized now, a variable BIND can only be inserted once.
so when she goes in the loop it does not ask to be told again, but takes the data you entered in the first IF, and presents the necessary messages.

Thanks for personal support. If I can solve this I present the answer here.
User avatar
dr_gori
Moderador
Moderador
Posts: 5026
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

It seems that the teacher took an example in C using "scanf" or in Java using

Select all

scan.nextLine();
and simply asked for the student to make the example in plsql.

Dai He thought: "Hmmm ... how to read the keyboard in Oracle? Oh, just put a & var".

But it is not the same
:-(
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest