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...
User is asked to enter a series of numbers. That input will stop when user enters...
User is asked to enter a series of numbers. That input will stop when user enters -9999. Find a maximum number from that series and a minimum number from that series. Output the location of Maximum number and minimum number.  Write a C++ program that asks the user to repeatedly input positive numbers until   -1 is pressed. Your program should print the second largest number and the count of even and odd numbers.  Write a C++ program that asks...
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),                ...
mySQL database question.. I have a database that has the following tables: User (Id, Name, Gender)...
mySQL database question.. I have a database that has the following tables: User (Id, Name, Gender) Primary key = Id Friends (Id1, Id2, Startdate) Primary key = (Id1, Id2) Foreign keys are also Id1, Id2 pointing to User(Id) Comments (CommentId, Poster, Recipient, Text, PostDate) Primary key = (CommentId) Foreign Keys are Poster, Recipient pointing to User(Id) I need to answer the following queries: 5. List Users who have posted comments to all female users 6. List User(s) who have received...
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.
JAVA) I need to get 10 integer numbers from the user. Then I need to find...
JAVA) I need to get 10 integer numbers from the user. Then I need to find sum of odd numbers, sum of even numbers, the lowest number of all numbers, the highest number of all numbers, and the average of all numbers( use double, with the two digit decimal) process; loopCount = 1 While LoopCount <= 10 Read number from the keyboard If odd, add to the total of all odd numbers If even, add to the total of all...
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 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...
Create a form in which the user enters two separate numbers (x and y), and when...
Create a form in which the user enters two separate numbers (x and y), and when the user clicks the appropriate button, math functions are performed on these two numbers and output back on to the form. INPUT User can enter two separate numbers (one for the x variable, and one for the y variable) User can input their information: The user must be able to enter information about themselves, including first name, last name, address, phone PROCESSING The user...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT