I want to add a constraint for the password column to ensure each password entered is atleast 6 characters but keep getting these errors CHECK errors
Question posted in PhpMyAdmin
The official documentation can be found here.
The official documentation can be found here.
2
Answers
ALTER TABLE documentation shows the syntax requires a contraint name:
Recommend not even playing with clear text passwords.If its worth learning its worth learning to do it correctly.
You set the tag to MySQL, so here is the correct syntax for MySQL server 8:
This won’t work on MariaDB 10, because the
ENFORCED
is not supported. In other words, it is useless.That said, the only alternative is to use a trigger:
This causes all new records to have a
NULL
password if they were too short. You would need another trigger for theUPDATE
.Of course, this all is insecure. Do not store plain-text passwords. You will not get hired / promoted. Only password hashes should be stored instead. These hashes usually have a fixed length, independent of the password’s length. The hashes are usually not generated / checked by the database, but in PHP. The length check thus usually doesn’t happen at the database level, but has to be moved to the application.