0
我已經使用angularjs創建了一個登錄名 - 我只是試圖將它傳遞給我的服務user.php以檢查憑證,然後在經過身份驗證後轉發。問題是,我的密碼是使用md5和im試圖弄清楚如何將這種編碼添加到從服務發送的數據中。AngularJS - 使用md5檢查登錄服務中的用戶/密碼密碼
登錄表單 - 的login.html
<div class="bs-example">
<form role="form" name="form1">
<div class="pgelogo"></div><p></p>
<div class="form-group">
<p>Welcome : <span>{{user.userid}}</span></p>
<label for="exampleInputEmail1">Userid</label>
<input type="text" placeholder="Enter name" class="form-control"
ng-model="user.userid" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" name="pass" placeholder="Password"
id="exampleInputPassword1" class="form-control" ng-model="user.pass"
required>
</div>
<button class="btn btn-default" type="submit" ng-click="login(user)"
ng-disabled="form1.$invalid">Submit</button>
<p>{{msgtxt}}</p>
</form>
</div>
控制器 - loginctrl.js
'use strict';
app.controller('loginCtrl', ['$scope','loginService',
function ($scope,loginService) {
$scope.msgtxt='';
$scope.login=function(data){
loginService.login(data,$scope); //call login service
};
}]);
指令 - logindrc.js
'use strict';
app.directive('loginDirective',function(){
return{
templateUrl:'partials/tpl/login.tpl.html'
}
});
服務 - loginservice.js
'use strict';
app.factory('loginService',function($http, $location, sessionService){
return{
login:function(data,scope){
var $promise=$http.post('data/user.php',data);
//send data to user.php
$promise.then(function(msg){
var uid=msg.data;
var pass=msg.data;
if(uid && pass){
//scope.msgtxt='Correct information';
sessionService.set('uid',uid);
//sessionService.set('lvl',level);
$location.path('/home');
}
else {
scope.msgtxt='incorrect information';
$location.path('/login');
}
});
},
logout:function(){
sessionService.destroy('uid');
//sessionService.destroy('lvl');
$location.path('/login');
},
islogged:function(){
var $checkSessionServer=$http.post('data/check_session.php');
return $checkSessionServer;
/*
if(sessionService.get('user')) return true;
else return false;
*/
}
}
});
** user.php的 - 檢查用戶身份驗證
ini_set("display_errors",1);
error_reporting(E_ALL);
//connect to db
require "../protected/db.php";
//$user=json_decode(file_get_contents('php://input'));
$user = $_SESSION['uid']=uniqid('ang_');
//$user = $_POST['uid'];
$pass = md5($_POST['pass']));
session_start();
if(isset($user) && isset($pass))
{
//get userid and level from users table according to
username and password entered
$sql = "SELECT userid,lvl FROM dbo.users WHERE userid = ? AND psw = ?";
$params = array($user, $pass);
$stmt = sqlsrv_query($conn,$sql,$params);
//if query does not work, return false
if($stmt === false){
die(print_r(sqlsrv_errors(), true));
}
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
if($row)
{
do{
//store users session for angular to handle
$_SESSION['uid']=uniqid('ang_');
$_SESSION['level'] = $row['lvl'];
//update the userlogin table with active user sesssion
$rec = "INSERT INTO dbo.user_login (
user_id,
time)
VALUES
(?,getdate())";
$recparams = array($user);
$s = sqlsrv_query($conn,$rec,$recparams);
if($s === false)
{
die(print_r(sqlsrv_errors(), true));
}
} while($row = sqlsrv_fetch_array($stmt));
}
session_destroy();
}
我能只用簡單的用戶名密碼進行身份驗證,但我需要的密碼爲編碼來檢查我的數據庫中的值。我得到錯誤500服務錯誤,意味着服務器端發生了什麼......只是不能指向它。任何有關這方面的幫助都會受到你們任何一位angularjs大師的讚賞。
發送密碼在明文,並散列在發球r,然後比較服務器上的兩個哈希值是否相等 –
md5已損壞,甚至不打擾 –
我想,我的問題也是如何分離用戶名和密碼在我的控制器發送到服務?現在,它將密碼分組,我似乎無法認證。 – MizAkita