Domanda

I am using Oracle 10.2.0.1

I have a table "AppUser" having Columns (id, username,pass,count)

i want to do is :

check username 
if (username exists )
{
check password
if (password exists)
{
set count = 0 and return 1
}
else (password not exists) 
{
check count < = 5
if true(count + 1 and return 0)
else return 2 (user locked)
}
}

i have made sequence "countid" minimum value =1, max value=5,inc by 1, cycle true.

now i want to make a package and call it from code behind.

i have this so far.. but it is giving me error ORA-00900: invalid SQL statement

IF count(select "LoginName" from "ApplicationUser" where exists (select "Count" from
"ApplicationUser" where Count<=5) and "LoginName" =:param1) >0
THEN select "Pass" from "ApplicationUser" where "Pass"=:param2;
ELSE return 0;
END IF;
È stato utile?

Soluzione 2

update usertable
    set count = 0
where id = @id

declare @i int, @Getpassword nvarchar(50),@GetCount int
set @i = 0 ;
while(@i <= 5)
begin


select @Getcount = count from usertable where id  = @id


if(@GetCount > 5 or @getCount = 5)
    begin
        -- block user here
        print 'user blocked'
        set @i = 6
    end
else 
    begin
        print 'checking'
        select @Getpassword = password from usertable where id = @id


        if(@Getpassword = @password)
            begin
                print 'validated'
                set @i = 6
            end
        else
            begin
                print 'not validated'
                set @i = @i + 1;
                print 'Current Count ' 
                print @getcount
                print 'updating count'
                update usertable
                    set count = @getcount +1 
                where id = @id
            end
        end
end
RETURN

Altri suggerimenti

What you try to do is quite complicated statement, that is hard to make and very hard to maintain and modify. Try to decompose your problem exactly as you wrote in your "i want to do is" section. PL/SQL gives you the possibility to write a nice decomposed code.

begin
select username into v_user_name where ...;
if (username is not null) then
    select password into v_password from ...;
    if (v_password is not null) then
        update AppUser set count = 0 where ...;
        return 1;
    else
        select count into v_count from ...;
        if v_count<5 then
            update AppUser set count=count+1 where....;
            return 0;
        else
            return 2;
        end if;
    end if;
end if;
end;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top