我有一個按鈕,您可以在其中輸入並重新輸入密碼來創建新密碼。
當兩者都相同時,密碼應存儲在手機的某處以供進一步使用。在設備上存儲密碼
目前我可以忽略密碼安全。
如何在設備上存儲和讀取密碼最簡單的方法?
btnLogin.TouchUpInside += delegate {
if(password.Exists /*My Isolated storage or password file*/){
ReturnToView();
} else{
new UIAlertView("Password doesn't exists", "Create a new password, to log in", null, "Ok").Show();
}
};
我已經試過這樣的事情,但我不知道如何檢查是否在.TXT
文件中存在的口令。
void CreateUser(){
IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
StreamWriter Writer = new StreamWriter(new IsolatedStorageFileStream("Password.txt", FileMode.OpenOrCreate, fileStorage));
btnCreateUser.TouchUpInside += delegate {
if(txtPassword.Text == txtRepeat.Text && txtPassword.Text.Length == 4){
GoBackToView(); //Login
Writer.WriteLine(txtPassword.Text);
Writer.Close();
} //here comes my else function, but that's not important.
};
}
在此之後,應該在.TXT
中創建一個密碼。 在一個名爲Login()
的新方法中,我將執行此操作。
IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
StreamReader Reader = null;
try
{
Reader = new StreamReader(new IsolatedStorageFileStream("Password.txt", FileMode.Open, fileStorage));
Reader.Close();
}
catch
{
MessageBox.Show("File it not created");
}
某處在我的登錄方法,我想,當我輸入密碼,以檢查是否創建的密碼,當我按我的登錄按鈕。
您可以使用NSUserDefaults的,如果你的應用程序正在使用CoreData您可以使用,以及。 –
你可以做一個代碼示例? – Lobbe
沒有犯法,但堆棧溢出不問任何代碼。請先嚐試一下。如果你卡在某個地方,我們可以幫忙。如果我沒有錯,你想爲應用程序創建一個登錄系統嗎? –