通过cron工作的防盗机制 [英] Anti-theft mechanism through cron job

查看:72
本文介绍了通过cron工作的防盗机制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚为android用户注册和登录编写了一个php脚本,它完美地工作但我需要添加

盗窃身份机制到脚本。以下是我的问题是否有一种方式可以让我这样做:


1.成功登录后立即通过cron作业自动破解用户名和密码

或用户登录30秒后,即如果用户退出应用程序并想要再次访问应用程序

,则必须注册。



2.有没有办法将密码锁定到设备的电话号码或imei。如果用户B想要使用用户A密码

,应用程序应提示或显示对话框其他用户已使用的密码。



请参阅下面的代码



<?php



class DbOperations {



private $ con;



函数__construct(){



require_once dirname(__ FILE __)。'/ DbConnect.php';



$ db = new DbConnect();



$ this-> con = $ db- > connect();



}



/ * CRUD - > C - >创建* /



公共功能createUser($ username,$ pass,$ email){

if($ this-> isUserExist( $ username,$ email)){

返回0;

}其他{

$密码= md5($ pass);

$ stmt = $ this-> con> prepare( INSERT INTO`user`(`id`,`username`,`password`,`email`)VALUES(NULL,?,?,?););

$ stmt-> bind_param(sss,$ username,$ password,$ email);



if($ stmt-> execute()){

返回1;

}否则{

返回2;

}

}

}



公共函数userLogin($ username, $ pass){

$ password = md5($ pass);

$ stmt = $ this-> con> prepare(SELECT id FROM users WHERE username =?AND密码=?);

$ stmt-> bind_param(ss,$ username,$ password);

$ stmt-> execute( );

$ stmt-> store_result();

返回$ stmt-> num_rows> 0;

}



公共函数getUserByUsername($ username){

$ stmt = $ this-> con - > prepare(SELECT * FROM users WHERE username =?);

$ stmt-> bind_param(s,$ username);

$ stmt - >执行();

返回$ stmt-> get_result() - > fetch_assoc();

}





私人函数isUserExist($ username,$ email){

$ stmt = $ this-> con> prepare(SELECT id FROM users WHERE username =?OR email =?);

$ stmt-> bind_param(ss,$ username,$ email);

$ stmt- >执行();

$ stmt-> store_result();

返回$ stmt-> num_rows> 0;

}



}



请帮助



我尝试了什么:



我在stackoverflow中发布了上述问题而gdg还没有回复

I just finished writing a php script for android user registration and login which is working perfectly but i need to add
a theft of identity mechanism to the script. Here are my questions is there a way for me to

1. make the username and password self destruct through cron job immediately after successfull login
or after 30 seconds login of the user i.e if the user logs out of the app and wants to access the app
again he will have to register.

2. Is there a way to make the password locked to phone number or imei of a device. If the user B wants to use user A password
the app should prompt or show dialog "password already in use by another user".

See my code below

<?php

class DbOperations{

private $con;

function __construct(){

require_once dirname(__FILE__).'/DbConnect.php';

$db = new DbConnect();

$this->con = $db->connect();

}

/*CRUD -> C -> CREATE */

public function createUser($username, $pass, $email){
if($this->isUserExist($username,$email)){
return 0;
}else{
$password = md5($pass);
$stmt = $this->con->prepare("INSERT INTO `users` (`id`, `username`, `password`, `email`) VALUES (NULL, ?, ?, ?);");
$stmt->bind_param("sss",$username,$password,$email);

if($stmt->execute()){
return 1;
}else{
return 2;
}
}
}

public function userLogin($username, $pass){
$password = md5($pass);
$stmt = $this->con->prepare("SELECT id FROM users WHERE username = ? AND password = ?");
$stmt->bind_param("ss",$username,$password);
$stmt->execute();
$stmt->store_result();
return $stmt->num_rows > 0;
}

public function getUserByUsername($username){
$stmt = $this->con->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s",$username);
$stmt->execute();
return $stmt->get_result()->fetch_assoc();
}


private function isUserExist($username, $email){
$stmt = $this->con->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
$stmt->bind_param("ss", $username, $email);
$stmt->execute();
$stmt->store_result();
return $stmt->num_rows > 0;
}

}

Kindly help

What I have tried:

I posted the above question in stackoverflow and gdg no response yet

推荐答案

con;



函数__construct(){



require_once dirname(__ FILE __)。'/ DbConnect.php';


con;

function __construct(){

require_once dirname(__FILE__).'/DbConnect.php';


db = new DbConnect();


db = new DbConnect();


this-> con =
this->con =


这篇关于通过cron工作的防盗机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆