Always got access denied in my login form

  angular, php

Here is my Code

login.component.html:

  <form [formGroup]="LoginForm" (ngSubmit)="onSignIn()">
    <div class="form">
      <div class="row form-group">
         <label for="" class="col-md-4">Username:</label>
         <input type="text" class="form-control col-md-7" placeholder="Username" 
        formControlName="usr_nm">
        </div>
        <div class="row form-group">
         <label for="" class="col-md-4">Password:</label>
         <input type="password" class="form-control col-md-7" placeholder="********" 
         formControlName="pswd">
         </div>
         <div class="button">
           <button type="submit" class="col-md-3" 
           [disabled]="!LoginForm.valid">Login</button>
         </div>
         <div class="forgot">
            <small>Forgot Your Password?<a href=""> Click Here!</a></small>
         </div>
        </div>
 </form>

          

login.component.ts:

import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { FormGroup,FormControl,Validators } from '@angular/forms';


@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
  LoginForm: FormGroup;
  url = "http://localhost/Cafeteria/";
  constructor(private http: HttpClient) { }

  ngOnInit(): void {
    this.LoginForm = new FormGroup({
      usr_nm: new FormControl("", Validators.required),
      pswd: new FormControl("", Validators.required)
    });
  }
  onSignIn(){
    console.log("SignIn");
    this.http.post(this.url + 'check1.php'
,JSON.stringify(this.LoginForm.value)).subscribe((res: any)=>{
         if(res.log_ok){
          console.log(res);
           alert("Welcome!");
         }else{
           alert("Access Denied!");
           console.log(res);
           //this.LoginForm.reset();
         }
      });
  }

}

code in check.php:

include 'connect.php';
$response = new stdClass();
    
if(isset($_POST['usr_nm'])){
$username = mysqli_real_escape_string($mysqli,$_POST['usr_nm']);
$password = mysqli_real_escape_string($mysqli,$_POST['pswd']);
    
$query = "SELECT cshracct_id FROM cashieraccount WHERE usr_nm='$username'    AND pswd=SHA1('$password')";
     
$response->log_ok = false;
if($result = $mysqli->query($query)){
 if($result->num_rows == 1){
   $response->cashieraccount = $result->fetch_object();
   $response->log_ok = true;
  }
 }
}
    
echo json_encode($response);

Source: Ask PHP

LEAVE A COMMENT