Skip to content

Instantly share code, notes, and snippets.

View codenannu's full-sized avatar

Nand kishor Shukla codenannu

  • Sangam Vihar, Delhi
View GitHub Profile
@codenannu
codenannu / php-brcypt-salt.php
Last active November 23, 2018 10:22 — forked from Greg-Boggs/php-brcypt-salt.php
Brcypt Salt In PHP
-----------------------------------------------
-- Create a mySQL table to hold hashed passwords and random salt
-- SQL create script for for table `users`
-----------------------------------------------
CREATE TABLE IF NOT EXISTS `users` (
`user_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(30) NOT NULL,
`reg_date` date NOT NULL,
`fname` varchar(20) DEFAULT NULL,
@codenannu
codenannu / bcrypt.php
Last active January 18, 2019 11:05 — forked from dzuelke/bcrypt.php
How to use bcrypt in PHP to safely store passwords (PHP 5.3+ only)
<?php
// secure hashing of passwords using bcrypt, needs PHP 5.3+
// see http://codahale.com/how-to-safely-store-a-password/
// salt for bcrypt needs to be 22 base64 characters (but just [./0-9A-Za-z]), see http://php.net/crypt
$salt = substr(strtr(base64_encode(openssl_random_pseudo_bytes(22)), '+', '.'), 0, 22);
// 2y is the bcrypt algorithm selector, see http://php.net/crypt
// 12 is the workload factor (around 300ms on my Core i7 machine), see http://php.net/crypt
$hash = crypt('foo', '$2y$12$' . $salt);