Criptare si decriptare parole cu mcrypt nu functioneaza
Scris: Sâm Oct 27, 2018
Salut, intampin cateva probleme cand incerc sa criptez parolele utilizatorilor.Problema e ca nu adauga parola criptata in Mysql dar o citeste daca o scriu eu normal.Insa, daca incerc sa ma loghez dupa ce mi-am facut contul nu se intampla nimic.Imi da eroare ca parola e gresita.Problema e ca in mysql dupa ce ma inregistrez nu se adauga si parola ci ramane spatiul alb.Cand adaug eu parola fara sa fie criptata o citeste la login.Nu am facut eu sistemul prin care se criptau parolele dar sper sa il pot reface eu ca incepator si eventual sa il imbunatatesc
Functiile adaugate pentru parole :
La register am urmatoare interogare:
Iar la login:
Baza de date am facut-o eu pentru ca vechea baza de date a fost pierduta:
Ca si cunostinte sunt incepator dar sper sa inteleg din explicatii.
Functiile adaugate pentru parole :
Cod: Selectaţi tot
public static function fnEncrypt($sValue, $sSecretKey)
{
return rtrim(
base64_encode(
mcrypt_encrypt(
MCRYPT_RIJNDAEL_256,
$sSecretKey, $sValue,
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(
MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_ECB
),
MCRYPT_RAND)
)
), "\0"
);
}
public static function fnDecrypt($sValue, $sSecretKey)
{
return rtrim(
mcrypt_decrypt(
MCRYPT_RIJNDAEL_256,
$sSecretKey,
base64_decode($sValue),
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(
MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_ECB
),
MCRYPT_RAND
)
), "\0"
);
}
Cod: Selectaţi tot
<?php
if(isset($_POST['submit_reg']))
{
$q = Config::$g_con->prepare('SELECT * FROM `users` WHERE `username` = ? OR `email` = ?');
$q->execute(array($_POST['username'],$_POST['email']));
if(!$q->rowCount())
{
if($_POST['password'] == $_POST['pass_conf'])
{
$Pass = "Passwort";
$crypted = Config::fnEncrypt($_POST['password'], $Pass);
$q = Config::$g_con->prepare('INSERT INTO `users` (`username`,`email`,`password`,`first_name`,`last_name`) VALUES (?,?,?,?,?)');
$q->execute(array($_POST['username'],$_POST['email'],$crypted,$_POST['first_name'],$_POST['last_name']));
echo '<strong><font color="green">You have registered with successful! Now you can login.</font></strong><br><br>';
} else echo '<strong><font color="red">Passwords aren\'t the same.</font></strong><br><br>';
} else echo '<strong><font color="red">This username or email already exists! Please choose another.</font></strong><br><br>';
}
?>
Cod: Selectaţi tot
<?php
if(isset($_POST['submit_login']))
{
$Pass = "Passwort";
$decrypt = Config::fnEncrypt($_POST['password'], $Pass);
$q = Config::$g_con->prepare('SELECT * FROM `users` WHERE `username` = ? AND `password` = ?');
$q->execute(array($_POST['username'],$decrypt));
if($q->rowCount())
{
while($row = $q->fetch(PDO::FETCH_OBJ))
{
$_SESSION['user_web'] = $row->ID;
header('location: '.Config::$_PAGE_URL.'index.php' );
}
} else {
echo '<strong><font color="red">Incorrect username or password!</font></strong><br><br>';
}
}
?>
Cod: Selectaţi tot
-- phpMyAdmin SQL Dump
-- version 4.7.7
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Oct 27, 2018 at 12:58 PM
-- Server version: 5.6.41
-- PHP Version: 5.6.30
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `website_website`
--
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`ID` int(11) NOT NULL,
`username` varchar(20) NOT NULL,
`password` varchar(56) NOT NULL,
`email` varchar(30) NOT NULL,
`first_name` varchar(11) NOT NULL,
`last_name` varchar(11) NOT NULL,
`validation` int(12) NOT NULL,
`staff` int(5) NOT NULL,
`currency` int(10) NOT NULL,
`Newsletter` int(2) NOT NULL,
`Skype` varchar(25) NOT NULL,
`Phone` int(25) NOT NULL,
`Birthday` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`Timezone` time(6) NOT NULL,
`Company Name` varchar(25) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`ID`, `username`, `password`, `email`, `first_name`, `last_name`, `validation`, `staff`, `currency`, `Newsletter`, `Skype`, `Phone`, `Birthday`, `Timezone`, `Company Name`) VALUES
(2, 'Administratie', '123456789', 'teste_administratie@yahoo.com', 'T', 's', 0, 1, 0, 1, 'support_adn', 0, '2018-10-27 09:57:55.376499', '00:00:00.000000', '');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`ID`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;