Question

In: Computer Science

I have 3 tables, but I need that when the user logs in and enters his...

I have 3 tables, but I need that when the user logs in and enters his login and password, it shows me only the information of that client. But it is showing me the information of all the clients.

Bank(mid,code,cid,sid,type,amount,mydate,note) from CPS300 This is the table where I want the information of a client to be seen

Customers(id,name,login,password) from CPS200

Sources(id,name) from CPS200

---------------------------------------------------------------------------------------------------------------------------------

for now I have two queries, but I must correct the one for client authentication because I must prevent SQL injections

SELECT c.login,c.password FROM CPS200.Customers c WHERE login='$username' or password='$password'"; (wrong query - SQL injections)

SELECT b.mid,b.code,b.type,b.amount,s.name as source,b.mydatetime,b.note
FROM CPS300.Bank as b
JOIN CPS200.Sources s ON b.sid=s.id;

Solutions

Expert Solution

which gives a pass to any 3 rd party user having any one of the credential of the user.

Query to get specific customer's information who gets logged in the system.

SELECT b.mid,b.code,b.type,b.amount,s.name as source,b.mydatetime,b.note
FROM ((CPS300.Bank as b
INNER JOIN CPS200.Sources s ON b.sid=s.id) INNER JOIN CPS200.Customers c ON c.id=s.id AND c.name=s.name) WHERE login='$username' AND password='$password';

The above query fetches ID and name of the customer according to their loginID and password and then using id and name of soucre table cpk(composite primary key) fetch the data from bank table to display the specific information of unique customer.

And alternatively you can also refer to query

select b.mid,b.code,b.type,b.amount,s.name as source,b.mydatetime,b.note from Bank b where b.sid=(select id from Sources where id =(select id from Customer WHERE login='$username' AND password='$password' ) and name= (select name from Customer WHERE login='$username' AND password='$password'))

The above query filters id and name from customer table for the given login credentials and uses that id and name to get id and name from the sources table which further makes a pull request to the bank table as per the fetched sid to print the requisite details.


Related Solutions

In C# When the user enters an invalid value, ask the user to repeatedly enter the...
In C# When the user enters an invalid value, ask the user to repeatedly enter the value until a valid value has been entered. Gender must be ‘M’ or ‘F’. Residency must be ‘I’ or ‘O’. Existing Code: using System; public class Student {   public int credit;   public String firstname, lastname, gender, residency, edate;   public void input()   {     Console.WriteLine("\nWelcome to the Continental University Registration System!"); Console.WriteLine("\nEnter data about a student"); Console.Write("First Name: "); firstname = Console.ReadLine(); Console.Write("Last Name: "); lastname...
Design JavaFX application with 7 labels and one textfield where user enters input inches.  When user enters...
Design JavaFX application with 7 labels and one textfield where user enters input inches.  When user enters his choice and presses enter key to complete input, program outputs resulting yards, feet, and inches.   Use class P5 that extends Application  with start method in it, and class P5Pane that extend GridPane. The only inctance variables for P5Pane class are inputInches where user enters input  inches, and three labels: outYards, outFeet, and outInches where program displays result of conversion.  Use the following names for instance variables:...
SQL- Trigger I have two tables (below) I need to write a trigger that would delete...
SQL- Trigger I have two tables (below) I need to write a trigger that would delete everything for a pid from the Appt table if the pid is deleted from the patient table. Create table Appt(                 pid numeric Foreign Key references patient(pid),                 ptname varchar(50) Foreign Key references patient(name),                 dob date Foreign Key references patient(dob),                 dr varchar(20),                 appdate date,                 apptime time, ); and Create table Patient(                 pid numeric primary key,                 name varchar(50),                ...
Database Design Design a database and show the relationship between each tables. I need multiple tables....
Database Design Design a database and show the relationship between each tables. I need multiple tables. *Must meet the requirements for Third Normal Form. These are the information for employee DB. Employee Number, First Name, Last Name, Date of birth, Address, city, state, zip, department, job title, supervisor, health insurance number, health insurance provider, dental insurance number, dental insurance provider, spouse/partner, children, children's ages.
I need to write a function that takes a user-provided string like 1-3-5, and output a...
I need to write a function that takes a user-provided string like 1-3-5, and output a corresponding series of letters, where A is assigned to 1, B is assigned to 2, C is assigned to 3, etc. So in the case of 1-3-5 the output would be ACE. For 2-3-4, it should print BCD. For ?-3-4 or --3-4 it should still print BCD. **CANNOT USE LISTS, SETS, DICTS, ETC. CANNOT USE SPLIT FUNCTION. ** Here is the code I have...
REQUIREMENT #3 Okay, I have a case study I need to complete by the end of...
REQUIREMENT #3 Okay, I have a case study I need to complete by the end of this week but I am stuck. Plus, I need to make sure that I am doing this correctly. It is a layered challenge. I will have to send the study in pieces because I could not attach the actual document.    Prepare a trial balance for July.     During its first month of operation, the Quick Tax Corporation, which specializes in tax preparation,              ...
I need to draw a cylinder in java with user input, and I can't seem to...
I need to draw a cylinder in java with user input, and I can't seem to get my lines to line up with my ovals correctly from the users input... I know I will have to either add or subtract part of the radius or height but I'm just not getting it right, here is how I'm looking to do it.            g.drawOval(80, 110, radius, height);            g.drawLine(?, ?, ?, ?); g.drawLine(?, ?, ?, ?);   ...
I NEED CALCULATION/PROCESSES TO UNDERSTAND IT. Company A, as lessee, enters into a lease agreement on...
I NEED CALCULATION/PROCESSES TO UNDERSTAND IT. Company A, as lessee, enters into a lease agreement on January 1, 2017, for equipment. The following data are relevant to the lease agreement: 1.   The term of the noncancelable lease is 4 years, with no renewal option. Payments of $845,378 are due on January 1 of each year. 2.   The fair value of the equipment on January 1, 2017 is $3,200,000. The equipment has an economic life of 6 years with an unguaranteed...
In Dominica, December 25 is Christmas. Given a year that a user enters, have your spreadsheet...
In Dominica, December 25 is Christmas. Given a year that a user enters, have your spreadsheet determine the date of Christmas. For example, if the user enters2030 as the year, your spreadsheet should display the date of Christmas is format 2030: Wd-Dec25. The formula should not display data is entered.
SQL tables(like pinterest) should have those tables user board pictures, likes follow pins comments Please write...
SQL tables(like pinterest) should have those tables user board pictures, likes follow pins comments Please write SQL for those questions 1. two users are friends if each has liked at least three pictures from the other user’s boards. Output all pairs of friends. 2. For each picture, output the number of times it has been re-pinned. 3. names of all users who follow a board containing a picture with the description “cactus at sunset”. IV. names of all users who...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT