Creating a login table in SQL - sql

My objective is to create a table that stores the information of the users and their passwords. Also, I want to keep track the number of failed logins. However, Here is a brief description about the tables:
First: the table of users
UserNo: ID of the user
Name: user's name
Email
Second: the table of login
UserNo: is the same as the last one
Password
Third: the table of tracking
UserNo
DateTime: date and time of login
count: counter that increases every time the user logins incorrectly.
From the last three tables, I do not think what I have done is a professional way. Is there any better ideas? especially with the tracking table.
Thanks

A couple of points:
There's no reason for your second table unless you're going to keep a password history (in which case you need an additional field to track the date the password was created)
In the third table, don't use a counter for the number of incorrect logins; instead, write a record for every login attempt (successful or otherwise), and use a query to retrieve the count whenever you need it.

Why are you keeping them separate? Why not just have a users table with the id, username, password hash, last login date and failed attempts counter?
Otherwise you could separate out login attempts to it's own table and record a status e.g. SUCCESS or FAIL so you can procedurally calculate number of failed attempts since the last successful one, and it also provides a full audit of logins, failed or not.

You might want to merge the first two tables together, as there is only one password per user, so it makes sense to have all the data for a user on one row in one table.
The third table records the timestamp of each login, and could also record the timestamp of each failed login if you added an extra column, then a quesy will give you a count of total failed logins per user.
Or, if you are counting the number of failed logins since last login, then you could just put the counter in the first table again.

You can put all your fields in a single table
UserID, UserName, UserEmail, Password, Login_Timestamp, Counter
then you can save all the values in a single table

Related

How to use loop to find related object using Pentaho Data Integration

I want to identify the bad/invalid records so that i can add in a separate SQL Table. For example, we have an account object. And i want to find bad accounts. But i need to apply some filters on contact object. If conditions satisfy based on contact then i want to inserts those invalid account records in SQL Table.
I don't want to directly query from contact. I want to query using account but conditions should be used from contact.
Do anyone knows what is the best way to perform loop in Pentaho? Check each record for contact , if all contact's condition satisfy then add Account id in table. If one of the contact record doesn't satisfy condition. The relevant account should not be added in SQL Table
For Example:
On Account "A" we have 10 contacts
if the email field is empty on all 10 contacts then add Account in SQL table(As bad data)
if on two of contact rcords has email field populated but 8 of them are blank then Account id shouldn't be added in SQL table
How we can better implement this scenario using Pentaho? Any help matters
Thanks
So you can create a transformation similar to this:
You have a query with the different account contacts
Order the query data by account
Group the information by accounts and calculate the maximum ContactMail (so if all mails in contacts are null, the max will be a null, is the result of that step is shown in the Preview data part of my screenshot)
Filter rows by MaxContactMail IS NOT NULL
These could be the basic steps, you'll need to add more steps or perform more than one transformation depending on the complexity of your data.

Retrieve all users with recent updates

Sql question.
I have a customer table with:
User id, name, email, phone
The customer can update their name, email and phone at anytime on an app.
How can I find out which user id had changes in name, email or phone number on a particular date?
Since your table doesn't store the date that they made the changes, you can't.
If you add a column with a datetime type (or whatever your specific database product provides) - you could call it LastModified or something like that - then the solution becomes trivial.
I'd give you a specific example, but because you didn't tell us what database engine you use, I can't guarantee to get the syntax right.
This is an issue with RDBMSes, you cannot as they generally store say a "photograph" of your data in time not a "film" of how it got there.
Based on the RDBMS you use, you can introduce an updated_at field which will hold when the last change happened to that row either from the "UPDATE" statement (say 'UPDATE phone=000, updated_at=now() WHERE user_id=999') or set it up to autoupdate see: create column for auto-date in postgresql

Defining Logged in Users Details in Oracle

I dont know how to go about defining a set of attributes to a user when they have logged in to Apex. After logging in with their username and password, the tables should display data about that User. The username and password are stored in a table with general details such as 'name','email address','home address etc' with 'Employee_id' being the primary key. When they have logged in they should have that specific row's data values. What I have tried to attempt:
I made a report want to specify the name display:
SELECT NAME
FROM EMPLOYEES
WHERE EMPLOYEE_USERNAME= :APP_USER
(Have tried to get the current logged in username).
This has not worked and nothing is displayed.
For your above query to return data the value of EMPLOYEE_USERNAME must match the current username which is stored in the :APP_USER variable. Please note that :APP_USER retrieves the username of the current user in uppercase. I suggest you change your query like this:
SELECT NAME
FROM EMPLOYEES
WHERE UPPER(EMPLOYEE_USERNAME)= :APP_USER
This type of query has some performance problems i suggest adding a trigger that will ensure the EMPLOYEE_USERNAME is in a uppercase or add a Function Based Index on UPPER(EMPLOYEE_USERNAME).

Invalid Login attempts in Perl

I am working on Login Form in perl. I wish to limit 3 times for invalid login attempts for 30 min. In which way shall I use. Give me some idea where to store the invalid login attempts.
You have a few different options:
Cookies - least secure, as different browsers, clearing cookies, etc. can all impact this. Not recommend but listed for completeness.
Database - if you are using a database then you can create a table that records every failed login attempt. Within this table login_attempts you record the following values: date, username. Then during any attempted login you (pseudo SQL) SELECT COUNT(*) FROM login_attempts WHERE username = '$the_user_name' AND date BETWEEN '$now' AND '$now-30m'. If the returned value is >= 3, deny the login. Make sure you create a clustered index on username and date descending. If you are concerned about space then you can have a job that runs nightly and removes any records with dates older than, say, 8 hours. (Though left in tact this serves as an audit log.)
File system - this option is so Byzantine I'm not going to go in-depth describing it, assuming you have some sort of database backing store already in place. If you have to go this route, then it looks like the database solution, above, without the SELECT statement and likely involves user names as directories with a file containing each login attempt and where the (mtime + 30m < now) will have to be true to permit a successful login. You'd need to make sure you have mtime enabled for the disk of course, or record the time within the file.

Sql query for specific data

I have an Archive Table. The columns are PK, Users and Logdatetime. When Users log in the system i am writing to archive table the user and datetime. A user can login more than one in one day.
The data in Logdatetime is like '2010-03-16 00:00:00.000'
I need to query all users FIRST Login time in one day and get the user with the datetime like:
user1 '2010-03-16 03:21:00.000'
user2 '2010-03-16 04:11:00.000'
It does not matter the users order.
I tried too many way but couldnt find a way. The only solution i found is the query for all users one by one. But it will take time. Any idea how to do this with a one query or more efficent way?
PS: I am using MS SQL Server 2005
Do you mean that you want the users very first login or the just first of a specific day?
This example query might lead you in the right direction;
SELECT [User], MIN(LogDateTime) AS FirstLogin FROM [Archive Table] GROUP BY [User]