Jose Fernandez
Jose Fernandez

Reputation: 23

Check Password on MySql

I'm new on MySql,

Problem:

CREATE TABLE Empleado (
    Usuario varchar(10) NOT NULL UNIQUE CHECK(LEN([Usuario]) = 10),
    Contraseña varchar(7) NOT NULL CHECK (
        LEN([Contraseña]) = 7 AND
        [Contraseña] LIKE '%[0-9]%[0-9]%' AND                                -- 2 numbers
        [Contraseña] LIKE '%[A-Za-z]%[A-Za-z]%[A-Za-z]%[A-Za-z]%[A-Za-z]%')  -- 5 letters
    )
);

IN SQL SERVER you can use LEN but in MYSQL what I must use?

Upvotes: 1

Views: 121

Answers (1)

danblack
danblack

Reputation: 14691

Yes, MySQL has CHECK CONTRAINTS.

You are however storing clear text passwords. This is strongly discouraged.

Recommend using password_hash or a similar application code for secure password storage..

To enforce the policy constraints, write this logic in application code.

Upvotes: 3

Related Questions