2017-03-13 2 views
1

ich erstelle Login mit Javascript und coderigniter mit CSRF und Ergebnis nach dem Login ist False, ob es etwas in meinem Code falsch ist.Fehler Login mit csrf und jquery Cookie in codeigniter

Mein CSRF:

$config['csrf_protection'] = TRUE; 
 
$config['csrf_token_name'] = 'st21Ol02sec94'; 
 
$config['csrf_cookie_name'] = 'true6log_suc'; 
 
$config['csrf_expire'] = 7200; 
 
$config['csrf_regenerate'] = TRUE; 
 
$config['csrf_exclude_uris'] = array();

meiner Sicht:

<?php echo form_open('',array('id' => 'form-loginx'));?> 
     <div class="input-group" style="margin-bottom:10px;"> 
      <span class="input-group-addon lab"><span class="glyphicon glyphicon-user"></span></span> 
      <input type="text" name="username" id="username" class="form-control inp usernamex" placeholder="username" required> 

     </div> 
     <div class="input-group" style="margin-bottom:10px;"> 
      <span class="input-group-addon lab"><span class="glyphicon glyphicon-lock"></span></span> 
      <input type="password" name="password" id="password" class="form-control inp passwordx" placeholder="password" required> 
     </div> 
     <button type="submit" name="submit" class="log_btn btn btn-md btn-primary">Login</button> 
     <label><input type="checkbox" class="lihat"> lihat password</label> 
     <?php echo form_close();?> 
     <?php echo br();?> 
    <div class="text-center">Copyright &copy; 2017 PT. Stars Internasional.</div> 
    <div class="text-center">server time <strong>{elapsed_time}</strong> secs.</div> 
     <?php echo br();?> 
    <div style="display:none;" class="alert-gagal"></div> 
    <div style="display:none;" class="alert-sukses"></div> 

mein javascript:

$('#form-loginx').submit(function(e){ // Create `click` event function for login 
     e.preventDefault(); 
     var csrf_hash = $.cookie('true6log_suc'); 
     var me = $(this).serialize(); 
     $.ajax({ // Send the credential values to another checker.php using Ajax in POST menthod 
      type : "POST", 
      url : baseURL + "trueaccon2194/info_type_user_log/log_admin", 
      data : {me,st21Ol02sec94: csrf_hash}, 
     beforeSend: function(){ 
      $('.log_btn').html('Loading ...'); //Loading button text 
      $('.log_btn').prop('disabled', true); 
     }, 
     success: function(log){ // Get the result and asign to each cases 
      $('.log_btn').html('Login'); //Loading button text 
      $('.log_btn').prop('disabled', false); 
      if(log == "openupsystemlogtrueaccess21"){ 
       $(".alert-sukses").html("Sedang mengarahkan..").slideToggle("fast").delay(3000).slideToggle("fast"); 
       window.location.href = 'trueaccon2194/info_type_user_log'; 
      }else if(log == "blockingaccesssystemlogerror210294"){ 
       $(".alert-gagal").html("Username atau password salah!").slideToggle("fast").delay(3000).slideToggle("fast"); 
       //location.reload(); 
      } 
      } 
      }); 
     return false; 
}); 

i verwenden j Abfrage Cookie und ob etwas mit meinem Code falsch ist

+0

Nur eine Idee, die ich seine besten finden virtuellen Host mit csrf dann normale localhost url – user4419336

+0

i localhost –

+0

Sie kann es auf xampp einfach bis So verwende ich zu verwenden, setzen https://www.youtube.com/watch?v= kD-tLlKS2ZI – user4419336

Antwort

0

Das Problem ist mit Daten in Ajax Anruf. Der "csrf_hash" in den Daten wird nicht den genauen Wert angeben.

Ersetzen Sie die csrf mit

$config['csrf_protection'] = TRUE; 
$config['csrf_token_name'] = 'st21Ol02sec94'; 
$config['csrf_cookie_name'] = 'true6log_suc'; 
$config['csrf_expire'] = 7200; 

In js

$('#form-loginx').submit(function(e){ // Create `click` event function for login 
e.preventDefault(); 
var csrf_hash = $.cookie('true6log_suc'); 
var dataObject = {}; 
dataObject[st21Ol02sec94] = csrf_hash; 
dataObject[me] = $(this).serialize(); 
$.ajax({ // Send the credential values to another checker.php using Ajax in POST menthod 
type : "POST", 
url : baseURL + "trueaccon2194/info_type_user_log/log_admin", 
data: dataObject, 
beforeSend: function(){ 
$('.log_btn').html('Loading ...'); //Loading button text 
$('.log_btn').prop('disabled', true); 
}, 
success: function(log){ // Get the result and asign to each cases 
$('.log_btn').html('Login'); //Loading button text 
$('.log_btn').prop('disabled', false); 
if(log == "openupsystemlogtrueaccess21"){ 
$(".alert-sukses").html("Sedang mengarahkan..").slideToggle("fast").delay(3000).slideToggle("fast"); 
window.location.href = 'trueaccon2194/info_type_user_log'; 
}else if(log == "blockingaccesssystemlogerror210294"){ 
$(".alert-gagal").html("Username atau password salah!").slideToggle("fast").delay(3000).slideToggle("fast"); 
//location.reload(); 
} 
} 
}); 
return false; 
}); 

Dies kann Ihnen helfen.