Free knowledge blog: linux, programming, open source, databases, android, frameworks, web and computing in general
A few days ago I did an exercise on a sales system in PHP. It is written in pure PHP, no Javascript. Mind you, for the styles I used a Bootstrap variant.
The files don’t have a structure, but like I said, it’s an example. I also write this because it either serves someone else or it serves myself for some references.
For data persistence it uses MySQL. This POS Save products and sales. It does not handle user permissions. We store the shopping cart in the session, and well, I better explain it in parts in this post.
Obviously this POS software is free and open source.
Today I am going to show you a software that I just made with Laravel. It is a sales system, point of sale, POS or whatever you call it, which is used to keep track of the products that are sold, the sales, and so on.
It is a totally free and open source system; which means that you can use it at no cost, and modify it to your needs or customize it. Among its features we find:
Now let’s see how I have developed it, where you can download it, and so on.
Although there are millions of tutorials about MySQL and PHP, I decided to make mine but in a very very simple way. Before you start, you must have a basic knowledge in MySQL.
It is worth mentioning that we will not see good practices of databases, relationships, etc. We will use the tables as they are, without looking at normalization, or things like that.
Note: this tutorial uses PDO, but remember that we can also use mysqli
functions. Personally I recommend PDO, because it is object oriented. However, I hope to write a tutorial about mysqli in the future.
Today we will see how to reset the OpenCart password (e-commerce system in PHP) manually, directly in the database; generating the hash and the salt manually with a function created by me.
Here I leave the code, and the explanation at the end.
The function returns an array that has the salt and the password, the way to call it is to pass the password in plain text. You can try and use the function here.
Once you have the salt and the password just do an update of your database table.
In my case:
My table is called oc_user
because when I installed OpenCart I used that prefix, in your case it can vary.
Thanks to OpenCart is open source we can see how it generates the salt and saves the hashes.
In its source code it implements obtaining a cryptographically secure random string and then uses sha1 to hash it, concatenating it with the user’s password.
The generation of the salt is as follows:
It uses the function called token
defined in helpers/general. php and then calls it, obtaining a random string of 9 digits. Then concatenate it and hash it with SHA1:
Finally, in the database it saves everything in the user table in the salt and password fields:
Knowing all those things we could write a function that generates the salt and the password to be able to reset the password of a user manually in OpenCart.
In this tutorial I will show how to install OpenCart in its version 3 on a server with PHP. You can mount it directly on a server in production, or on your localhost for testing.
Sometimes we need to create a random string or token using PHP. For example, it’s quite common that when we want to reset our password on some website a message is sent to the mail we registered.
Probably the message have a link like this:
site.com/reset-pass?token=123
Where 123 is the token. Today we will see how to create a token cryptographically secure using PHP. We can use this token as a password or as random string to reset something.
This works for PHP 5 and for PHP 7.