Last active
June 24, 2025 09:40
-
-
Save zmts/b72d3bcfd07634ff519da407bb86f361 to your computer and use it in GitHub Desktop.
Revisions
-
Sasha Zmts revised this gist
Mar 11, 2017 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,7 +52,6 @@ var myHash = bcrypt.hashSync('123456', sol); Первые 29 символов и есть соль __$2a$10$ydKFuX0Jfxsega193bReze__ p.s. - https://habrahabr.ru/post/210760/ - https://habrahabr.ru/post/130965/ - https://www.youtube.com/watch?v=rCIsuMEFRro -
Sasha Zmts revised this gist
Nov 11, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ ## Авторизация существующего юзера 1. Юзер вводит в поле авторизации некий пароль 2. Берем соль из базы и данный пароль 3. Солим только что полученный пароль, в итоге получаем хеш 4. Берем валидную хеш из БД и сравниваем ее с только что полученным хешем 5. Profit, если введенный пароль вырный авторизируем, если нет говорим юзеру ввести правильный пароль -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,7 @@ bcrypt.compare("some_password", hash_from_db, function(error, result) { } }); ``` ### Откуда bcrypt.compare берет соль ``` var sol = bcrypt.genSaltSync(); >> '$2a$10$ydKFuX0Jfxsega193bReze' -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,9 +8,9 @@ ## Авторизация существующего юзера 1. Юзер вводит в поле авторизации некий пароль 2. Берем соль из базы и данный пароль 3. Солим только сто полученный пароль, в итоге получаем хеш 4. Берем валидную хеш из БД и сравниваем ее с только что полученным хешем 5. Profit, если введенный пароль вырный авторизируем, если нет говорим юзеру ввести правильный пароль Суть не в дешифровке хеша из базы и сверке его с введенным паролем, а в создании нового хеша из нового введенного юзером пароля и соли из базы и последующей сверкой нового хеша с хешем из БД. -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,6 +52,7 @@ var myHash = bcrypt.hashSync('123456', sol); Первые 29 символов и есть соль __$2a$10$ydKFuX0Jfxsega193bReze__ p.s. https://habrahabr.ru/post/210760/ https://habrahabr.ru/post/130965/ -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -53,4 +53,5 @@ var myHash = bcrypt.hashSync('123456', sol); p.s. https://habrahabr.ru/post/210760/ https://habrahabr.ru/post/130965/ -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,3 +50,7 @@ var myHash = bcrypt.hashSync('123456', sol); >> '$2a$10$ydKFuX0Jfxsega193bRezezqVklYDdrYSAHk5ho1uE8CPDuqNA8p6' ``` Первые 29 символов и есть соль __$2a$10$ydKFuX0Jfxsega193bReze__ p.s. https://habrahabr.ru/post/210760/ https://habrahabr.ru/post/130965/ -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,7 @@ bcrypt.compare("some_password", hash_from_db, function(error, result) { } }); ``` ### Про то откуда bcrypt.compare берет соль ``` var sol = bcrypt.genSaltSync(); >> '$2a$10$ydKFuX0Jfxsega193bReze' -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,8 +42,11 @@ bcrypt.compare("some_password", hash_from_db, function(error, result) { }); ``` ### Про то откуда bcrypt.compare бедет соль ``` var sol = bcrypt.genSaltSync(); >> '$2a$10$ydKFuX0Jfxsega193bReze' var myHash = bcrypt.hashSync('123456', sol); >> '$2a$10$ydKFuX0Jfxsega193bRezezqVklYDdrYSAHk5ho1uE8CPDuqNA8p6' ``` Первые 29 символов и есть соль __$2a$10$ydKFuX0Jfxsega193bReze__ -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,8 +42,8 @@ bcrypt.compare("some_password", hash_from_db, function(error, result) { }); ``` ### Про то откуда bcrypt.compare бедет соль var sol = bcrypt.genSaltSync(); >> '$2a$10$ydKFuX0Jfxsega193bReze' var myHash = bcrypt.hashSync('123456', sol); >> '__$2a$10$ydKFuX0Jfxsega193bReze__zqVklYDdrYSAHk5ho1uE8CPDuqNA8p6' -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,12 +41,9 @@ bcrypt.compare("some_password", hash_from_db, function(error, result) { } }); ``` ### Про то откуда bcrypt.compare бедет соль var sol = bcrypt.genSaltSync(); >> '$2a$10$ydKFuX0Jfxsega193bReze' var myHash = bcrypt.hashSync('123456', sol); >> '__$2a$10$ydKFuX0Jfxsega193bReze__zqVklYDdrYSAHk5ho1uE8CPDuqNA8p6' -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,4 +40,13 @@ bcrypt.compare("some_password", hash_from_db, function(error, result) { // авторизируем юзера } }); ``` Про то откуда бедет соль ``` var sol = bcrypt.genSaltSync(); >> '$2a$10$ydKFuX0Jfxsega193bReze' var myHash = bcrypt.hashSync('123456', sol); >> '__$2a$10$ydKFuX0Jfxsega193bReze__zqVklYDdrYSAHk5ho1uE8CPDuqNA8p6' ``` -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,5 +40,4 @@ bcrypt.compare("some_password", hash_from_db, function(error, result) { // авторизируем юзера } }); ``` -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,11 +20,10 @@ https://github.com/dcodeIO/bcrypt.js ``` var bcrypt = require('bcryptjs'); bcrypt.genSalt(10, function(error, salt) { // генерим соль >> передаем ее в колбек bcrypt.hash("some_password_from_input", salt, function(error, hash) { // берем пароль из инпута + соль и генерим хеш // получаем хеш и сохраняем в БД // в случае использования bcryptjs необходимость хранения соли отпадает, почему объясняется ниже }); }); ``` -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,9 +31,9 @@ bcrypt.genSalt(10, function(error, salt) { // герерим соль >> пер ## Практическое применение: проверка хешей 1. Берем пароль из инпута, хеш из БД(hash_from_db) 2. Ф-ция compare сама извлекает соль из хеша(hash_from_db) и солит им нововведенный пароль 3. И сверивает новый хеш с хешем из БД(hash_from_db) Вот почему мы не сохраняли соль в БД, bcryptjs сам знает как извлечь соль из хеша, и унас отпадает необходимость хранить соль отдельно ``` bcrypt.compare("some_password", hash_from_db, function(error, result) { -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 8 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,14 +30,16 @@ bcrypt.genSalt(10, function(error, salt) { // герерим соль >> пер ``` ## Практическое применение: проверка хешей 1. Берем пароль из инпута, хеш из БД 2. Ф-ция compare сама извлекает соль из хеша и солит им пароль 3. И сверивает новый хеш с хешем из БД Вот почему мы не сохраняли соль в БД, bcryptjs сам знает как извлечь соль из хеша, и унас отпадает необходимость хранить соль отдельно ``` bcrypt.compare("some_password", hash_from_db, function(error, result) { if (result){ // авторизируем юзера } }); ``` -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 17 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,18 +13,31 @@ 4. Берем валидную хеш из БД и сравниваем ее с только что полученной хешЮ 5. Profit, если введенный пароль вырный авторизируем, если нет говорим юзеру ввести правильный пароль Суть не в дешифровке хеша из базы и сверке его с введенным паролем, а в создании нового хеша из нового введенного юзером пароля и соли из базы и последующей сверкой нового хеша с хешем из БД. ## Практическое применение: создание хеша https://github.com/dcodeIO/bcrypt.js ``` var bcrypt = require('bcryptjs'); bcrypt.genSalt(10, function(error, salt) { // герерим соль >> передаем ее в колбек bcrypt.hash("some_password_from_input", salt, function(error, hash) { // берем пароль из инпута + соль и генерим Хеш // получаем хеш и сохраняем ее в БД // в случае использования bcryptjs необходимость хранения соли отпадает // почему объясняется ниже }); }); ``` ## Практическое применение: проверка хешей ``` // берем пароль из инпута, хеш из БД // ф-ция compare сама извлекает соль из хеша и солит им пароль // и сверивает новый хеш с хешем из БД // вот почему мы не сохраняли соль в БД // bcryptjs знает как извлечь соль из хеша, и унас отпадает необходимость хранить соль отдельно bcrypt.compare("some_password", hash_from_db, function(error, result) { }); ``` -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,9 @@ 4. Берем валидную хеш из БД и сравниваем ее с только что полученной хешЮ 5. Profit, если введенный пароль вырный авторизируем, если нет говорим юзеру ввести правильный пароль Суть не в дешифровке хеша из базы и сверке его с введенным паролем, а в создании нового хеша из нового введенного юзером пароля и соли из базы и последующей сверкой нового хеша с хешем из БД ## Приактическое применение: создание хеша https://github.com/dcodeIO/bcrypt.js ``` var bcrypt = require('bcryptjs'); @@ -23,4 +25,6 @@ bcrypt.genSalt(10, function(error, salt) { // герерим соль >> пер // получаем Хеш и сохраняем ее в БД }); }); ``` ## Приактическое применение: проверка хешей -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,9 +17,10 @@ https://github.com/dcodeIO/bcrypt.js ``` var bcrypt = require('bcryptjs'); bcrypt.genSalt(10, function(error, salt) { // герерим соль >> передаем ее в колбек bcrypt.hash("some_password_from_input", salt, function(error, hash) { // берем пароль из инпута + соль и генерим Хеш // получаем Хеш и сохраняем ее в БД }); }); ``` -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 12 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,19 @@ 4. Записываем хеш(не пароль) в БД + соль в отдельном филде ## Авторизация существующего юзера 1. Юзер вводит в поле авторизации некий пароль 2. Берем данный пароль, берем соль из базы 3. Солим только сто полученный пароль, в итоге получаем хеш 4. Берем валидную хеш из БД и сравниваем ее с только что полученной хешЮ 5. Profit, если введенный пароль вырный авторизируем, если нет говорим юзеру ввести правильный пароль ## Приактическое применение https://github.com/dcodeIO/bcrypt.js ``` var bcrypt = require('bcryptjs'); bcrypt.genSalt(10, function(err, salt) { bcrypt.hash("B4c0/\/", salt, function(err, hash) { // Store hash in your password DB. }); }); ``` -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 14 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,15 @@ # Про хранение паролей в БД ## При создании нового юзера 1. При регистрации юзер вводит некий пароль 2. Генерим случайную соль индивилуально для каждого юзера 3. Создаем хеш на основе введенного юзером пароля и соли 4. Записываем хеш(не пароль) в БД + соль в отдельном филде ## Авторизация существующего юзера 1. Юзер вводит в поле авторизации пароль 123456 2. Берем данный пароль, берем соль из базы 3. Солим только сто полученный пароль, в итоге получаем хеш 4. Берем валидную хеш из БД и сравниваем ее с только что полученной хешЮ 5. Profit -
Sasha Zmts revised this gist
Nov 10, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,2 @@ # Про хранение паролей в БД - Пароль хранится в виде -
Sasha Zmts renamed this gist
Nov 10, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Sasha Zmts created this gist
Nov 9, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ 1