IsolatedStorage实现软件登陆时的密码验证

Login.xaml:

public partial class Login : PhoneApplicationPage
{
private const string pwd = "pwd";

public Login()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Login_Loaded);
}

void Login_Loaded(object sender, RoutedEventArgs e)
{
if (!IsolatedStorageSettings.ApplicationSettings.Contains(pwd))
{
textBlock.Text = "请设定密码:";
}
}

private void buttonReset_Click(object sender, RoutedEventArgs e)
{
textBox.Text = "";
}

private void buttonOK_Click(object sender, RoutedEventArgs e)
{
if (!IsolatedStorageSettings.ApplicationSettings.Contains(pwd))
{
IsolatedStorageSettings.ApplicationSettings[pwd] = textBox.Text;
IsolatedStorageSettings.ApplicationSettings.Save();
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
else
{
if (textBox.Text.Equals(IsolatedStorageSettings.ApplicationSettings[pwd] as string))
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
else
{
textBlock.Text = "请重新输入:";
textBox.Text = "";
}
}
}
}

MainPage.xaml:

public partial class MainPage : PhoneApplicationPage
{
private const string pwd = "pwd";

// 构造函数
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
this.BackKeyPress += new EventHandler<System.ComponentModel.CancelEventArgs>(MainPage_BackKeyPress);
}

void MainPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBoxResult msgRst = MessageBox.Show("要退出到登陆界面吗?", "提示", MessageBoxButton.OKCancel);
if (msgRst == MessageBoxResult.Cancel)
{
e.Cancel = true;
}
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
textBlock.Text = IsolatedStorageSettings.ApplicationSettings[pwd] as string;

}

}
原文地址:https://www.cnblogs.com/liubaicai/p/2306705.html