您的位置:首页 > 其它

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

2011-12-29 21:57 363 查看
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;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: