2

我正在创建一个网站,我试图在其中创建一个表单,将用户输入发送到我的谷歌文档/驱动器中的谷歌电子表格......我找到了一个 Github 项目,可以让人们编写 php 代码......它包括脚本所需的 2 个其他 php 文件。代码如下:

我的问题是,如何在 $u = / $p = 下隐藏我的密码?任何查看代码的人都可以看到我的密码。我该如何防止这种情况发生?

脚本来源的链接是:http: //www.farinspace.com/saving-form-data-to-google-spreadsheets/

<?php

// Zend library include path
set_include_path(get_include_path() . PATH_SEPARATOR . "$_SERVER[DOCUMENT_ROOT]/ZendGdata-1.8.1/library");

include_once("Google_Spreadsheet.php");

$u = "username@gmail.com";
$p = "password";

$ss = new Google_Spreadsheet($u,$p);
$ss->useSpreadsheet("My Spreadsheet");
$ss->useWorksheet("wks2");

// important:
// adding a leading alpha char prevents errors, there are issues 
// when trying to lookup an identifier in a column where the 
// value starts with both alpha and numeric characters, using a
// leading alpha character causes the column and its values to be 
// seen as a strictly a strings/text

$id = "z" . md5(microtime(true));

$row = array
(
    "id" => $id // used for later lookups
    , "name" => "John Doe"
    , "email" => "john@example.com"
    , "comments" => "Hello world"
);

if ($ss->addRow($row)) echo "Form data successfully stored";
else echo "Error, unable to store data";

$row = array
(
    "name" => "John Q Doe"
);

if ($ss->updateRow($row,"id=".$id)) echo "Form data successfully updated";
else echo "Error, unable to update spreadsheet data";

?>
4

3 回答 3

2

您可以尝试使用下面的代码隐藏 if 从凝视的眼睛。如果您尝试过,它仍然可以被发现,但至少它远离打开的文本视图。它所做的只是在文本中添加字符,然后在使用密码之前减去它们。

使用您的原始密码运行此脚本

<?php
$password = "test";

echo "Original Password In Plain Text = $password\n";
$len=strlen($password);

$NewPassword = "";
for( $i = 0; $i <= $len-1; $i++ ) {
$charcode = ord(substr( $password, $i, 1 ));
$NewChar = $charcode+5; $NewLetter = chr($NewChar);
$NewPassword = $NewPassword . $NewLetter;
} echo "Modified Password to Use in Script = $NewPassword\n";

$OrigPassword = "";
for( $i = 0; $i <= $len-1; $i++ ) {
$charcode = ord(substr( $NewPassword, $i, 1 ));
$OrigChar = $charcode-5; $OrigLetter = chr($OrigChar);
$OrigPassword = $OrigPassword . $OrigLetter;
} echo "Convert the Modified back to the Original = $OrigPassword\n";

?>

使用上述脚本中的新密码将此部分添加到您的脚本中

$password = "yjxy";
$OrigPassword = "";
for( $i = 0; $i <= $len-1; $i++ ) {
$charcode = ord(substr( $password, $i, 1 ));
$OrigChar = $charcode-5; $OrigLetter = chr($OrigChar);
$OrigPassword = $OrigPassword . $OrigLetter;
} $password = $OrigPassword;
echo "Script thinks this is the password = $password\n";

于 2014-12-09T19:07:13.060 回答
1

隐藏密码的最佳方法是将其保存在外部文件中,然后将其包含在您的 php 脚本中。假设您使用此密码的文件config.php应该在上方DOCUMENT_ROOT以使其无法通过浏览器访问。这是常见的方法,例如,您可以在 Zend Framework 目录结构中看到它,其中只有“公共”目录对用户可见。适当的 CHMOD 也应该设置到这个文件中。

此链接下,您有 ZF 目录结构,您可以在其中检查配置文件的位置。

于 2013-06-10T10:12:13.267 回答
0

这个问题已经在这里被问过很多次(但不是专门针对谷歌文档)。简短的回答是你无能为力。

更长的答案是,您可以通过以下方式降低凭据被破坏的可能性:

  • 使用提供给用户而不是存储在代码中的凭据
  • 使用用户提供的令牌作为解密存储在您的代码中的凭据的一种方式(但是这对于很多用户来说变得非常复杂)
  • 将凭据存储在文档根目录之外的包含文件中
于 2013-06-10T09:39:27.027 回答