Membalikkan md5

hendra · Feb 16, 2015
Selamat siang mas
Saya lagi belajar membuat form login, sebenar nya form login nya sudah jalan dgn baik. Waktu saya lihat di database nya (mysql) passwordnya tidak ter-enkripsi,jadi saya menggunakan fungsi md5. Tapi waktu saya login dengan password yang sudah di enkripsi menjadi tidak bisa masuk ke aplikasi nya (gagal login).

Mohon bantuannya teman2,
Disini saya lampirkan scrip loginnya.


salam
// file untuk login
<?php
	session_start();
	require_once('include/connection.php');

	function clean($str) {
		$str = @trim($str);
		if(get_magic_quotes_gpc()) {
			$str = stripslashes($str);
		}
		return mysql_real_escape_string($str);
	}

	$login = clean($_POST['user']);
	$password = clean($_POST['pass']);
	$qry="SELECT * FROM m_user WHERE nm_user='$login' AND pass_user='$password'";
	$result=mysql_query($qry);

	if($result) {
		if(mysql_num_rows($result) == 1) {
			session_regenerate_id();
			$member = mysql_fetch_assoc($result);
			$_SESSION['SESS_ID'] = $member['id'];
			$_SESSION['SESS_NAME'] = $member['nm_user'];
			/*$_SESSION['SESS_DEPT'] = $member['dept'];*/
			session_write_close();
			header("location: member-index.php");
			exit();
		}else {
			header("location: index.php?usr=1");
			exit();
		}
	}else {
		die("Query failed");
	}
?>
// file untuk simpan dara user dengan menggunakan Enkripsi md5
<?php
include "auth.php";
include("include/connection.php");
?>
  
<html>
<head>
<title>Warehouse Application</title>
<!-- css file included -->
  <link rel="stylesheet" type="text/css" href="css/style.css" />
  <link rel="stylesheet" href="css/calendar.css">
  <link rel="stylesheet" href="css/menu-item1.css" media="screen" type="text/css">
  <link rel="stylesheet" href="css/menu-bar1.css" media="screen" type="text/css">
  <link href="greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all" />
  <link href="static_files/help.css" rel="stylesheet" type="text/css" media="all" />
<!-- css file included end -->

<!-- Java script funct -->
<script language="JavaScript" type="text/javascript">
    function hide(x) { document.getElementById(x).style.display='none'; }
    function show(x) { document.getElementById(x).style.display=''; }
    var GB_ROOT_DIR = "./greybox/";

function deldata(txt_deptcd, nm_dept)
 {
  if (confirm("Anda yakin ingin menghapus data Wilayah : " + nm_wiek + ""))
   {
      window.location.href = 'wiek_sv.php?tipe=delete&del=' + txt_no;
   }
 }
</script>
<!-- Java script funct end-->

<!-- Java Script Included -->
  <script type="text/javascript" src="js/menu-for-applications.js"></script>
  <script type="text/javascript" src="greybox/AJS.js"></script>
  <script type="text/javascript" src="greybox/AJS_fx.js"></script>
  <script type="text/javascript" src="greybox/gb_scripts.js"></script>
  <script type="text/javascript" src="static_files/help.js"></script>
  <script language="JavaScript" src="js/calendar_us.js"></script>
<!-- Java Script Included end -->



</head>
<center>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (index.psd) -->
<table id="Table_01" width="800" border="0" cellpadding="0" cellspacing="0">
	<tr><td colspan="3">&nbsp;</td></tr>
	<tr>
		<td background="img/img_01.png" width="20" height="53">
		</td>
		<td background="img/img_02.png" width="762" height="53"><h2>WAREHOUSE APPLICATION
		</h2></td>
		<td background="img/img_03.png" width="18" height="53"></td>
	</tr>
	<tr>
        <td colspan="3" width="800">
           <table width="792.5" border="0" align="center" cellpadding="0" cellspacing="0">
             <TR><TD><?php include "menu.html"; ?></TD></TR>
           </table>
        </td>
	</tr>

	<tr>
		<td background="img/img_07.png" width="20" height="51"></td>
		<td background="img/img_08.png" width="762" height="51">ADMINISTRATOR</td>
		<td background="img/img_09.png" width="18" height="51"></td>
	</tr>
	<tr>
		<td background="img/img_10.png" width="20" height="19"></td>
		<td background="img/img_11.png" width="762" height="19"></td>
		<td background="img/img_12.png" width="18" height="19"></td>
	</tr>
	<tr>
		<td background="img/img_13.png" width="20"></td>
		<td width="762" align="center">

                    <form name="admin" method="POST" action="">
   	   <table width="628" border="0"/>

<?php

if (isset($_POST['submit'])){
    if($_POST['username'] | !$_POST['passwd1'] | !$_POST['passwd2'])
	
	{
	    echo'<p> Klik <a href="admin.php">Untuk Kembali</a> </p>' ;
	
        die("Anda tidak melengkapi semua field");
    }
    if (!get_magic_quotes_gpc()){
        $username=addslashes($_POST['username']);
        $passwd1=addslashes($_POST['passwd1']);
        }
//memeriksa username jika terjadi kesamaan nama user
    $usercheck=$_POST['username'];
    $sql=mysql_query("SELECT nm_user FROM m_user WHERE nm_user='".$usercheck."'")or die(mysql_error());
    $check=mysql_num_rows($sql);

    if ($check !=0){
	   echo'<p> Klik <a href="admin.php">Untuk Kembali</a> </p>';
       die("<b>MAAF, Nama : ".$_POST['username']." sudah digunakan</b>");
	   //echo'klik <a href="index.php"> disini</a>';
			   
        }else if($_POST['passwd1'] != $_POST['passwd2']){
		echo'<p> Klik <a href="admin.php">Untuk Kembali</a> </p>';
     die("Password Anda tidak sama, <b>Confirm Password</b>");

        }

    //menambahkan user baru
//        $enkrip_pass=md5($passwd1);
		$enkrip_pass=md5($passwd1);
        $query="INSERT INTO m_user(nm_user, pass_user) VALUES('$username','$enkrip_pass')";
        $sql=mysql_query($query)or die(mysql_error());
?>
      <h1>Registered</h1>
<p>Terimakasih Anda Telah Melakukan Regristrasi - Jika Mau Login.
Click <a href="admin.php">here</a> for Login</p>
<?php
}else{
?>
<form action="" method="post" name="Register">
<table width="332" border="0">
<tr>
<td width="127">Username:</td>
<td width="163"> <input type="text" name="username" maxlength="60" size="20"></td></tr>
<tr>
  <td>Password:</td><td> <input type="password" name="passwd1" maxlength="10" size="10"></td></tr>
<tr>
  <td>Confirm Password:</td><td> <input type="password" name="passwd2" maxlength="10" size="10"></td></tr>
  
<tr><th colspan="2">&nbsp;&nbsp;<input type="submit" name="submit" value="Register"></th></tr>
</table>
</form>

              
	
      </form>        </td>
		<td background="img/img_15.png" width="18"></td>
	</tr>
	<tr>
	<td background="img/img_16.png" width="20" height="34"></td>
	<td background="img/img_17.png" width="762" height="34"></td>
        <td background="img/img_18.png" width="18" height="34"></td>
	</tr>
	<tr>
	  <td colspan="3" align="center">Copyright &#169; IT PT MEGA TRUKINDO UTAMA (2014)</td>
        </tr>
  </table> <!-- End ImageReady Slices -->
<?php
}
?> 
<script type="text/javascript">
	var menuModel = new DHTMLSuite.menuModel();
	DHTMLSuite.configObj.setCssPath('css/');
	menuModel.addItemsFromMarkup('menuModel');
	menuModel.setMainMenuGroupWidth(00);
	menuModel.init();
	var menuBar = new DHTMLSuite.menuBar();
	menuBar.addMenuItems(menuModel);
	menuBar.setTarget('menuDiv');
	menuBar.init();
</script>

</body>
</center>
</html>

Silahkan login untuk menjawab!
0
Loading...
Redo Kusuma · Feb 26, 2015 · 0 Suka · 0 Tidak Suka
untuk login kita harus mencocokkan password kedatabase, dimana password tersebut sudah hash MD5, jadi untuk login kita ubah dulu password yng disubmit user ke database...

contoh
$pass = md5($_POST); //nama field database, di ubah jadi md5 juga
"SELECT * FROM user where user='$user' and password='$pass'"
kurang lebih begitu sob... jangan lupa mampir untuk download source code php pemula
0
Loading...
Redo Kusuma · Apr 3, 2015 · 0 Suka · 0 Tidak Suka
md5 itu hash satu arah, tidak bisa di balik...
mungkin maksud pertanyaan agan, ketika login maka passwordnya di konvert md5...
mungkin tutorial ini bisa membantu, TUTORIAL LOGIN SYSTEM DENGAN PHP MYSQL mYSQLi