14
Июн
2017

Как зашифровать пароль в md5 и чтоб работал в логин форме?

Как зашифровать пароль в md5 и чтоб работал в логин форме?
Я добавил в if md5 , но в логине не считывает пароль и пишет ошибку

include("../database/db_conection.php");
if(isset($_POST['register']))
{
    $user_name=$_POST['name'];
    $user_lastname=$_POST['lastname'];
    $user_email=$_POST['email'];
    $user_position=$_POST['position'];
    $user_country=$_POST['country'];
    $user_pass=$_POST['pass'];
    $user_copass=$_POST['copass'];
    $salt="h4T3hd9Fse";

    if($user_name=='')
    {
        //javascript use for input checking
        echo"<script>alert('Please enter the name')</script>";
        exit();//this use if first is not work then other will not show
    }

    if($user_position=='')
    {
        echo"<script>alert('Please enter the position')</script>";
        exit();
    }

    if($user_country=='')
    {
        echo"<script>alert('Please enter the country')</script>";
        exit();
    }

    if($user_pass=='')
    {
        echo"<script>alert('Please enter the password')</script>";
        exit();
    }

    if ($user_pass != $user_copass)
    {
        echo"<script>alert('Error... Passwords do not match')</script>";
        exit();
    }else{
        $user_pass=md5($salt.$user_pass);
        $user_copass=md5($salt.$user_copass);
    }

    if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)){
        echo"<script>alert('Please enter the email')</script>";
        exit();
    }
    //here query check weather if user already registered so can't register again.
    $check_email_query="select * from users WHERE user_email='$user_email'";
    $run_query=mysqli_query($dbcon,$check_email_query);

    if(mysqli_num_rows($run_query)>0)
    {
        echo "<script>alert('Email $user_email is already exist in our database, Please try another one!')</script>";
        exit();
    }
    //insert the user into the database.
    $insert_user="insert into users (user_name,user_pass,user_email,user_lastname,user_position,user_country,user_copass) VALUE ('$user_name','$user_pass','$user_email','$user_lastname','$user_position','$user_country','$user_copass')";
    if(mysqli_query($dbcon,$insert_user))
    {
        echo"<script>window.open('../../index.php','_self')</script>";
    }

}

Логин php

session_start();//session starts here

include("database/db_conection.php");

if(isset($_POST['login']))
{
    $user_email=$_POST['email'];
    $user_pass=$_POST['pass'];

    $check_user="select * from users WHERE user_email='$user_email'AND user_pass='$user_pass'";

    $run=mysqli_query($dbcon,$check_user);

    if(mysqli_num_rows($run))
    {
        echo "<script>window.open('welcome.php','_self')</script>";

        $_SESSION['email']=$user_email;//here session is used and value of $user_email store in $_SESSION.

    }
    else
    {
        echo "<script>alert('Email or password is incorrect!')</script>";
    }
}

Источник: https://ru.stackoverflow.com/questions/679411/%D0%9A%D0%B0%D0%BA-%D0%B7%D0%B0%D1%88%D0%B8%D1%84%D1%80%D0%BE%D0%B2%D0%B0%D1%82%D1%8C-%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%8C-%D0%B2-md5-%D0%B8-%D1%87%D1%82%D0%BE%D0%B1-%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0%D0%BB-%D0%B2-%D0%BB%D0%BE%D0%B3%D0%B8%D0%BD-%D1%84%D0%BE%D1%80%D0%BC%D0%B5

Share

Тебе может это понравится...