gpt4 book ai didi

c# - 用户名和密码数据 Windows Phone 8 应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 20:09:30 24 4
gpt4 key购买 nike

我正在编写一个 Windows Phone 8 应用程序,该应用程序使用 API 提取应用程序需要的一些数据并使用该 API,需要用户名和密码。我已获得此用户名和密码,它似乎有效,但我想知道在应用程序中使用此用户名和密码的正确方法是什么?

我可以简单地添加如下内容吗:

string userName = "username";
string passWord = "password";

然后在需要时将它们传递到 WebRequest 中?还是我应该以某种特殊方式将此信息存储在应用程序中?

需要说明的是,用户不需要自己的用户名或密码,这个通用的应该可以。

最佳答案

您可以加密隔离存储中的数据。 Here是教程

以防链接失效,这里是用于写入和读取 secret PIN 的应用代码。

using System.IO;
using System.IO.IsolatedStorage;
using System.Text;
using System.Security.Cryptography;

private string FilePath = "pinfile";

private void BtnStore_Click(object sender, RoutedEventArgs e)
{
// Convert the PIN to a byte[].
byte[] PinByte = Encoding.UTF8.GetBytes(TBPin.Text);

// Encrypt the PIN by using the Protect() method.
byte[] ProtectedPinByte = ProtectedData.Protect(PinByte, null);

// Store the encrypted PIN in isolated storage.
this.WritePinToFile(ProtectedPinByte);

TBPin.Text = "";
}

private void WritePinToFile(byte[] pinData)
{
// Create a file in the application's isolated storage.
IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream writestream = new IsolatedStorageFileStream(FilePath, System.IO.FileMode.Create, System.IO.FileAccess.Write, file);

// Write pinData to the file.
Stream writer = new StreamWriter(writestream).BaseStream;
writer.Write(pinData, 0, pinData.Length);
writer.Close();
writestream.Close();
}

private void BtnRetrieve_Click(object sender, RoutedEventArgs e)
{
// Retrieve the PIN from isolated storage.
byte[] ProtectedPinByte = this.ReadPinFromFile();

// Decrypt the PIN by using the Unprotect method.
byte[] PinByte = ProtectedData.Unprotect(ProtectedPinByte, null);

// Convert the PIN from byte to string and display it in the text box.
TBPin.Text = Encoding.UTF8.GetString(PinByte, 0, PinByte.Length);

}

private byte[] ReadPinFromFile()
{
// Access the file in the application's isolated storage.
IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream readstream = new IsolatedStorageFileStream(FilePath, System.IO.FileMode.Open, FileAccess.Read, file);

// Read the PIN from the file.
Stream reader = new StreamReader(readstream).BaseStream;
byte[] pinArray = new byte[reader.Length];

reader.Read(pinArray, 0, pinArray.Length);
reader.Close();
readstream.Close();

return pinArray;
}

关于c# - 用户名和密码数据 Windows Phone 8 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21007033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com