Column encryption with pgcrypto #627
Answered
by
ftonato
kmiyashiro
asked this question in
Questions
|
I was looking into encrypting a sensitive column and read about the |
Answered by
ftonato
Feb 1, 2021
Replies: 1 comment 21 replies
|
Hey @kmiyashiro, As you already know, Supabase allows the use of Although this is normally used for sensitive data (passwords), you can use it for whatever you want. Below is an example of how to use it: # Create table users
CREATE TABLE users (id SERIAL PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
password TEXT NOT NULL);
# Insert a new user
INSERT INTO users (email, password)
VALUES ('kmiyashiro@mail.com', crypt('kmiyashiropassword', gen_salt('bf')));
# Fetch the user ID using his/her email and encrypted password
SELECT id
FROM users
WHERE email = 'kmiyashiro@mail.com'
AND password = crypt('kmiyashiropassword', password);
# This will return one row with the correct user ID
# | id |
# |---------|
# | 1 |
# | (1 row) |Note: You can use this encryption for any field that you consider important. I hope I've helped 🎸 |
21 replies
Answer selected by
kmiyashiro
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @kmiyashiro,
As you already know, Supabase allows the use of
pgcrypto.Although this is normally used for sensitive data (passwords), you can use it for whatever you want.
Below is an example of how to use it: