对于想了解PHP用户名密码解决方案的读者,本文将是一篇不可错过的文章,我们将详细介绍php用户名密码解决方案怎么写,并且为您提供关于gitpull/push项目的时候总是提示要输入用户名密码的解决方案
对于想了解PHP用户名密码解决方案的读者,本文将是一篇不可错过的文章,我们将详细介绍php用户名密码解决方案怎么写,并且为您提供关于git pull/push项目的时候总是提示要输入用户名密码的解决方案、git 用户名密码配置、git 缓存用户名密码、git 记住用户名密码的有价值信息。
本文目录一览:PHP用户名密码解决方案(php用户名密码解决方案怎么写)
我正在开发我的第一个基于PHP的网站,我想知道用户名/密码系统有哪些解决方案?我已经尝试使用.htaccess文件来实现基本的安全性,虽然它有效但我希望外行人能够管理一些更容易的东西.我可以尝试其他解决方案吗?我没有可用的数据库服务器,所以它必须支持平面文件数据库…谢谢!
编辑我已经确定我有sqlite支持,所以我确实有一个数据库选项可用.另外,我觉得我应该再提一些我的要求.我原本期望使用.htaccess来保护我的网站,因为我需要整个目录的安全性.我试图保护的大多数文件都是.pdf和.doc …任何解决方案都必须允许我保护这些文件以及目录中的任何网页.
如果我能找到一个很好的解决方案或多或少的“皮肤”锁定目录的.htaccess方法,这样我可以做一些事情,比如有一个实际的登录/注册页面等等,那么我只会坚持.htaccess方法.然而,我想要一些更易于管理的东西,我只需要目录安全性.
解决方法:
我快速编写了这段代码,它在语法上是正确的,但我还没有测试过.
有两件事我没有在这里做,首先,我没有提供删除用户的功能,第二件我没有提供更改用户密码的功能,这些你必须自己写.
但是,这应该是一个好的起点.
这些函数将以下列格式将您的用户名/密码存储在名为passwords的文件中
username0:password0
username1:password1
username2:password2
...
.
function authenticate($username, $password)
{
//ALWAYS use a salt to secure the encryption of your passwords, this can be any value of any
//length, the longer and the more characters the better
//I like to use a "perfect password" from Steve Gibbson's https://www.grc.com/passwords.htm
//This must the exactly the same as the salt in theaddUser() function
$salt = 'voDeaFWckErOPPGwiapYBwEoc4O2d1M60m2QsYc7A15PUshrLamoVioG1wUmEgF';
//First we need to get the contents of the file that has the usernames/passwords in it.
//we don't want to use fopen() or we may end up with a locked file error if another access is
//attempted before we've closed it.
//this line will get the contents of the file named passwords and store it in the $fh variable
$fh = file_get_contents('passwords');
//Now lets take the file and split it into an array where each line is a new element in the array.
$fh = split("\n", $fh);
//Now lets loop over the entire array spliting each row into it's username/password pair
foreach($fh as $r)
{
//Every time this loop runs $r will be populated with a new row
//Lets split the line into it's username/password pairs.
$p = split(':', $p);
//Since we don't need all the usernames/password to be in memory lets stop when we find the one we need
if($p[0] == $username && $p[1] == sha1($salt . $password))
{
//We've found the correct use so lets stop looping and return true
return true;
}
}
//If we've reached this point in the code then we did not find the user with the correct password in the 'database'
//so we'll just return false
return false;
}
function addUser($username, $password)
{
//ALWAYS use a salt to secure the encryption of your passwords, this can be any value of any
//length, the longer and the more characters the better
//I like to use a "perfect password" from Steve Gibbson's https://www.grc.com/passwords.htm
//This must the exactly the same as the salt in the authenticate() function
$salt = 'voDeaFWckErOPPGwiapYBwEoc4O2d1M60m2QsYc7A15PUshrLamoVioG1wUmEgF';
//We need to parse out some preticularly bad characters from the user name such as : which is used to seperate the username and password
//and \r and \n which is the new line character which seperates our lines
$username = preg_replace('/\r|\n|\:/', '', $username);
//Now lets encrypt our password with the salt added
$password = sha1($salt . $password);
//Lets build the new line that is going to be added
$line = $username . ':' . $password . "\n";
//Lets open the file in append mode so that the pointer will be placed at the end of the file
$fh = fopen('passwords', 'a');
//Write the new entry to the file
fwrite($fh, $line);
//Close the file
fclose($fh);
//Typicaly one would write a bunch of error handling code on the above statments and if something
//goes wrong then return false but if you make it this far in the code then return true
return true;
}
git pull/push项目的时候总是提示要输入用户名密码的解决方案
出处:http://www.manks.top/article/git_tip_user_password
本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
问题是很简单,解决起来也是很简单,我们在终端输入一行代码即可
git config --global credential.helper store
git 用户名密码配置
1、设置用户名
$ git config --global user.name "your name"
2、设置邮箱
$ git config --global user.email "your email"
2、设置密码
$ git config --global user.password "your password"
3、查看所有配置
$ git config --list
git 缓存用户名密码
<table><tbody><tr>
<td><pre>1
2
3
总结
以上是小编为你收集整理的git 缓存用户名密码全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
git 记住用户名密码
方式一:
1.在用户文件夹下新建 _netrc 文件,在文件内写入以下内容:
machine git.oschina.net
login username
password password
方式二、
在用户文件夹下新建.gitconfig文件,第一次会提示输入用户名和密码,第二次以后会记住。
[credential]
helper = store
关于PHP用户名密码解决方案和php用户名密码解决方案怎么写的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于git pull/push项目的时候总是提示要输入用户名密码的解决方案、git 用户名密码配置、git 缓存用户名密码、git 记住用户名密码的相关信息,请在本站寻找。
本文标签: