How can I create an MD5 field using Laravel Migration script? - mysql

I need to create a password field. I couldn't find anything similar in Laravel Migration document.
Please help.

There is no md5 datatype in Databases. Make a varchar field for password. And put your md5 encrypted data in there.

Related

Mysql encryption/decryption without sending password in query

I need to encrypt some specific columns in mysql database. I researched and found few ways like AES_ENCRYPT functions, but these solutions requires sending the key value in the query.
I am looking for a solution where password can be stored in database some location and mysql can automatically use that value to encyrpt or decrypt that particular column?
Thank you.

How to get hash value of a text saved in a database

I'm working with a web application and I want to get the hash value of the text which is saved in a MySQL database table,I'm new to this field and I'm using Spring-MVC for the web application,can any one please help me?
By hash, are you talking about any specific hashing function? A common one that you can use is md5, which mysql supports:
select md5(some_column) from some_table;
Here's a link to the reference: Mysql Reference/Encryption Functions

MySQL ENCRYPT field to MD5

I am having trouble to transfer email user account which is saved in MySQL to another server. Here is the detail:
I have an old email server which using MySQL to store user account information. The password field uses MySQL ENCRYPT function to save the users password. So if I want change the user's password I can do:
UPDATE `mail`.`users` SET `password` = ENCRYPT( '12345' ) WHERE CONVERT( `users`.`email` USING utf8 ) = 'g#veecall.com' LIMIT 1 ;
Then the new password "12345" saved in the table as string of " 2I6JOeg.JukJ."
Now I build a new server using iRedMail. When I try to transfer user account I have trouble to transfer the password field. Because the iRadMail/dovecot is using MD5-CRAM to encrypt the password then save it in the MySQL. All the password string is started with "$1$".
So, is there a way to make the MySQL encrypted password string "2I6JOeg.JukJ." convert to MD5 hash "$1$................."?
Thanks for help.
Firstly MD5 is a hashing algorithm not a encryption algorithm. The main reason for this is that it is virtually impossible to calculate the original password from the hash value generated by MD5. MD5 creates a hash value and it basically a trap door function in other words it is a one way function.
Encryption will allow you to encrypt and decrypt IF you knew the key. Big difference. Hope you understand that.
Now for your problem.
Unless you have the original password before it was encrypted there is no reasonable way besides brute force to create the MD5 equivalent of the password. The encrypted passwords hash and the unecrypted/plain text password hash will be two different think.
If you can decrypt all the passwords you currently have to their plain text form you can perform the MD5 hashing on the plain text values. If you cannot get the original plain text then you are out of luck.

MySQL chops off characters from md5 password

I'm developing a website locally using XAMPP. There is a registration page in which I save the password, after encrypting it with MD5, to a MySQL database. The problem is that when I try to log in, I'm unable to. I discovered that the password was the problem. I checked the database and compared the MD5-ed password with the one I logged in with (I just echoed the MD5 hash of the password onto the page to compare). I found that the one in the database was shorter than the one echoed. My conclusion was that MySQL was chopping off some characters at the end of the hash. What should I do? I know it has to do with some settings on MySQL but I need help.
As at now, I have to use substr function on the hash in the registration and login processes so as to be able to log in.
If the column length is causing the problem, alter the column to accept a longer length. MD5's are always 32 hex digits, so VARCHAR(32) would be a good option.
It depends by the length of the value in the database ... check your field in the database and verify that his type is atleast something like a varchar(32)
To fix it you can use a query like that
ALTER TABLE Example
MODIFY password varchar(32)
or use the phpMyAdmin interface

LONGTEXT valid in migration for PGSQL and MySQL

I am developing a Ruby on Rails application that stores a lot of text in a LONGTEXT column. I noticed that when deployed to Heroku (which uses PostgreSQL) I am getting insert exceptions due to two of the column sizes being too large. Is there something special that must be done in order to get a tagged large text column type in PostgreSQL?
These were defined as "string" datatype in the Rails migration.
If you want the longtext datatype in PostgreSQL as well, just create it. A domain will do:
CREATE DOMAIN longtext AS text;
CREATE TABLE foo(bar longtext);
In PostgreSQL the required type is text. See the Character Types section of the docs.
A new migration that updates the models datatype to 'text' should do the work. Don't forget to restart the database. if you still have problems, take a look at your model with 'heroku console' and just enter the modelname.
If the db restart won't fix the problem, the only way I figured out was to reset the database with 'heroku pg:reset'. No funny way if you already have important data in your database.