如何使用Taylor Hornby的密码散列函数(How to use Taylor Hornby's password hashing functions)
我一直在读密码哈希。 我真的不擅长PHP。 谁能告诉我如何使用Taylor Hornby的密码散列函数?
I have been reading about password hashing. I really am not great at php. Could anyone tell me how to use Taylor Hornby's password hashing functions as seen here?
原文:https://stackoverflow.com/questions/24579611
更新时间:2024-05-13 21:05
最满意答案
我假设每个用户都在自己的行上。
您可以将
array_slice
用于此目的。 然后,您可以根据切片值重写文件。$filepath = "usernames.txt"; // convert file to array $file = file($filepath); // get first 40 elements $file = array_slice($file, 0, 40); // rewrite usernames file file_put_contents($filepath, implode("", $file));
如果您的服务器上有cron,则可以随时添加cron作业来自动处理此脚本。
编辑:
请尝试使用此脚本。
$filepath = "usernames.txt"; // reverse array to get first elements at the top; convert file to array $file = array_reverse(file($filepath)); // get first 40 elements $file = array_slice($file, 0, 40); // reverse array back; rewrite usernames file file_put_contents($filepath, implode("", array_reverse($file)));
EDIT2:
$file = file($filepath); if(in_array($submittedUsername, $file)) { $i = array_search($submittedUsername, $file); unset($file[$i]); } // then save username to the file
I assume that every user is on its own line.
You could use
array_slice
for that purpose. Then you can rewrite file based on sliced values.$filepath = "usernames.txt"; // convert file to array $file = file($filepath); // get first 40 elements $file = array_slice($file, 0, 40); // rewrite usernames file file_put_contents($filepath, implode("", $file));
You can add cron job to handle this script automatically whenever you want, if you have cron on your server.
Edit:
Try this script instead.
$filepath = "usernames.txt"; // reverse array to get first elements at the top; convert file to array $file = array_reverse(file($filepath)); // get first 40 elements $file = array_slice($file, 0, 40); // reverse array back; rewrite usernames file file_put_contents($filepath, implode("", array_reverse($file)));
Edit2:
$file = file($filepath); if(in_array($submittedUsername, $file)) { $i = array_search($submittedUsername, $file); unset($file[$i]); } // then save username to the file
相关问答
更多-
试着这样做: for u in $(也许这种方法适合你的需要:) class User; QDebug operator<< (QDebug d, const User &user); QTextStream& operator<< (QTextStream& os, const User& user); class User { public: User(); User(QString data); bool setData(const QString &data); int id() c ...如果只有两个值,则可以使用min()和max()执行此操作: SELECT t.teamName, t.teamImage, f.fileType, min(u.username) as user1, (case when max(u.username) > min(u.username) then max(u.username) end) as user2 FROM userleague ul INNER JOIN users u ON u.userI ...您可以使用以下查询: SELECT usernames, picURLs FROM table1 INNER JOIN table2 ON table2.usernames = table1.usernames inner join table2.usernames = table1.usernames用于使用条件table2.usernames = table1.usernames将两个表连接在一起。 我将建议您阅读有关SQL Joins更多信息,然后您可以轻松地执行此类查询。 注意: ...在您的第一个表达式中,如果您转义了点\. ,它将匹配\. 在最后一个之前.*? 你的第二个表达只是清楚地匹配整行。 要匹配但排除@你可以做.. 对于域使用: ^@(\S+\.[^\s]+)$ 正则表达式: ^ the beginning of the string @ '@' ( group and capture to \1: \S+ non-whitespace (all but \n, \r, \t, \f, ...
如何在将新用户名提交到.txt文件时删除旧用户名?(How to delete old usernames when new usernames are submitted to .txt file?)[2023-06-21]
我假设每个用户都在自己的行上。 您可以将array_slice用于此目的。 然后,您可以根据切片值重写文件。 $filepath = "usernames.txt"; // convert file to array $file = file($filepath); // get first 40 elements $file = array_slice($file, 0, 40); // rewrite usernames file file_put_contents($filepath, implo ...打开文件后,您可以使用readlines()将文本读入用户名/密码对列表。 由于您使用空格分隔了用户名和密码,因此每对都是看起来像'Na19XX myPassword'字符串,您可以使用split()其split()为两个字符串的列表。 从那里,检查用户名和密码是否与用户输入匹配。 如果您希望多个用户的TXT文件增长,则需要在每个用户名/密码对之后添加换行符。 def register(): username = input("Please input the first 2 letters of ...实现用户名来设计(Implementing usernames to devise)[2023-09-14]
如果您使用username而不是email作为身份验证密钥,那么您必须已定义: #config/initializers/devise.rb config.authentication_keys = [:username] - 或者,您可以在模型中定义身份验证密钥,如下所示: devise :database_authenticatable, :authentication_keys => [:username] 将以下方法添加到用户模型中以避免对电子邮件进行验证: def email_required ...您无需事先知道行数。 只需用fscanf()读取名称和密码对,直到它返回EOF 。 while (fscanf(fp, "%s %s", accounts[j].id, accounts[j].password) != EOF) { ++j; } 另外,不要使用feof() 。 它通常不会像你期望的那样工作。 feof()仅在程序尝试读取文件并失败后才返回true值。 也就是说,它不会阻止您的循环尝试读取文件末尾。 You don't need to know the number of line ...诀窍在于validateUser函数: 只需将while语句放在while循环之外: 原因是: - while循环运行,它检查文本文件中的第一行,它失败然后落入'else',然后调用userBack函数,这意味着未检查文本文件的其余部分。 void validateUser() throws Exception{ BufferedReader getIt = new BufferedReader(new InputStreamReader(System.in)); ...相关文章
更多- 【转】Java's hashCode is not safe for distributed systems
- Linux下SSH免密码登录
- The Log: What every software engineer should know about real-time data's unifying abstraction
- She’s Not Carrying A Handbag
- Redis 客户端连接、密码验证、连接数设置
- Storm,yahoo!S4比较
- Just Forget To Ask The Handbag's Name
- Lua 函数定义与使用
- 【课程分享】基于Lucene4.6+Solr4.6+Heritrix1.14+S2SH实战开发从无到有垂直搜索引擎
- Hadoop集群搭建之SSH无密码登录配置
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)