如何在我的应用程序中保存用于api的第三方应用程序的密码? [英] How save password of a third party application in my app for use with a api?

查看:76
本文介绍了如何在我的应用程序中保存用于api的第三方应用程序的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的PHP应用程序中保存一个第三方应用程序密码,以便在后台进程中连接到API。我需要将密码存储在数据库中,并且密码是针对应用程序的每个用户的。但是我不知道保存它以供以后检索的正确方法是什么。

I need to save a third-party application password in my PHP application for connect to a API in a background process. I need store the password in a DB, and the password is for each user of the application. But I don´t know what is the correct way to save it for retrieve it after.

我不想保存没有加密的密码,但是我不愿意不知道哪种方法是最好的(简便)

I don´t want to save the password without encryption, but I don´t know which is the best method (and easy) to do this

有什么想法吗?

推荐答案

除非对该API有某种OAuth机制可用,否则您最好将其存储为纯文本格式。一旦攻击者可以访问密码的加密形式,那么他们很可能就可以访问解密该密码的代码。

Unless there's some sort of OAuth mechanism available for the API you might as well store it in plain text. Once an attacker has access to the encrypted form of the password then they more than likely have access to the code that decrypts it.

我的首选方法是:

inc.credentials.php

inc.credentials.php

<?php
$app_creds = array(
  'username' => 'sammitch',
  'password' => 'isgreat'
);

actual_code.php

actual_code.php

<?php
require('inc.credentials.php');
app_login($app_creds['username'], $app_creds['password']);
unset($app_creds);




  1. 始终使用通过PHP解释器运行的文件扩展名,以便文件不会作为纯文本。

  2. 始终不使用结束符?> ,因此不会意外输出任何内容。 [最有可能的空格]

  3. unset()主要是偏执狂,但只是在代码注入的情况下。

  1. Always uses a file extension that's run through the PHP interpreter so that the file will not be served as plain text.
  2. Always leave off the closing ?> so nothing is accidentally output. [most likely whitespace]
  3. unset() is mostly paranoia, but just in case of code injection.

这篇关于如何在我的应用程序中保存用于api的第三方应用程序的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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