简体   繁体   English

如何使用户/密码在php脚本中安全?

[英]How to make user/pass secure in php scripts?

My application is a website for online purchase. 我的应用程序是一个在线购买网站。 I (php server) will collect client's requests and send them to the processing gateway. 我(PHP服务器)将收集客户端的请求,并将其发送到处理网关。 The gateway cannot directly talk to the clients, and it requires my authentication details to have communication with me. 网关无法直接与客户端对话,并且需要我的身份验证详细信息才能与我进行通信。 Because clients need to get immediate response from the gateway while online, so I have to put my authentication details in my server-side php script. 因为客户端需要在线时从网关获得立即响应,所以我必须将身份验证详细信息放在服务器端php脚本中。 I know that's not safe. 我知道那不安全。 So how can I make it secure? 那么如何确保它安全呢?

Thanks! 谢谢!

Since your script has to be able to get your username/password for the payment gateway, regardless of how "securely" you store them, at some point they'll be exposed in raw unencrypted form, even if only in memory. 由于您的脚本必须能够获取支付网关的用户名/密码,所以无论您如何“安全地”存储它们,在某些时候它们都将以未加密的原始形式公开,即使它们仅在内存中也是如此。

The problem boils down to how much time and effort you want to spend "securing" the user/pass, vs. how much it'd cost you to clean up after a compromise. 问题归结为您要花费多少时间和精力来“保护”用户/密码,而不是妥协后清理多少钱。 Let's say you spend $2000 in time/effort securing your site. 假设您花费了$ 2000的时间/精力来保护自己的网站。 The effort pays off an no one breaks in. However, it would only have cost you $100 in fines after a break in, so you've got a net loss of $1900. 付出的努力无可厚非,可是您付出了最大的努力。但是,一次中断后您只需支付100美元的罚款,因此您净亏损1900美元。

A basic way to do this is put the auth details into a file maybe init.inc and place this file outside of the web root. 一种基本方法是将auth详细信息放入文件init.inc中,然后将此文件放置在Web根目录之外。 So you might have 所以你可能有

 - \site_directory\ 
      - \secure_include\
           - init.inc
      - \siteroot\
           - \css\
           - \includes\
           - \images\
           - login.php

This way at the very least if anything goes wrong with apache + php parser the plain text files will not be viewable in a web browser. 这样,至少在apache + php解析器出现任何问题的情况下,纯文本文件将无法在Web浏览器中查看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM