2014-10-05 41 views
1

我正在爲Windows 8.1,C#和.NET Framework 4.5.1開發Windows應用商店應用程序。我想使用PasswordBox.SecurePassword但它似乎不可用。我已經將框架版本更改爲4.5,我已經嘗試使用.NET Framework 4.5.1進行WPF測試項目,但它不可用。PasswordBox.SecurePassword在WinRT Store App上不可用

我試圖將PresentationFramework.dll程序集添加到我的Windows 8.1 Store應用程序,但是我不能。

我試圖做到這一點:

{ 
    PasswordBox pass = new PasswordBox(); 
    pass.SecurePassword // I'm checking if it is available 
} 

要檢查是否SecurePassword存在,但SecurePassword不適用於Windows應用商店的應用程序。

是否在Windows應用商店應用中提供SecurePassword

回答

0

恐怕說,Windows應用商店的應用程序無法使用SecureString的
您應該使用Windows.Security.Credentials的方法和對象

10/07夜(日本時間)改寫
我想你希望的喜歡登錄工作,不要這樣做?
如果「Windows.Security.Credentials命名空間」是一個簡單的解決方案。

請看看上面的代碼

CS文件

//MainPage.xaml.cs 
using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Runtime.InteropServices.WindowsRuntime; 
using Windows.Foundation; 
using Windows.Foundation.Collections; 
using Windows.UI.Xaml; 
using Windows.UI.Xaml.Controls; 
using Windows.UI.Xaml.Controls.Primitives; 
using Windows.UI.Xaml.Data; 
using Windows.UI.Xaml.Input; 
using Windows.UI.Xaml.Media; 
using Windows.UI.Xaml.Navigation; 
using Windows.Security.Credentials; 

namespace App1 
{ 

public sealed partial class MainPage : Page 
{ 
    PasswordVault vault = new PasswordVault(); 

    public MainPage() 
    { 
     this.InitializeComponent(); 
     this.NavigationCacheMode = NavigationCacheMode.Required; 

     //Initialize Credential data 
     try 
     { 
      var alldata = vault.FindAllByResource("My List"); 
      foreach (PasswordCredential data in alldata) 
      { 
       vault.Remove(data); 
      } 
     } 
     catch { } 
    } 
    protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
    } 

    private void Button_Click(object sender, RoutedEventArgs e) 
    { 
     //Certificate for Input data 
     PasswordCredential credential = null; 
     try 
     { 
      credential = vault.Retrieve("My List", Username.Text); 

      if(credential.Password==password.Password)    
      { 
       Status.Text = "Status : Succeed in Certificating"; 
      } 
      else 
      { 
       Status.Text = "Status : Failed to Certification"; 
      } 
     } 
     catch { Status.Text = "Status : Failed to Certification"; } 
    } 

    private void Button_Click_1(object sender, RoutedEventArgs e) 
    { 
     //Registar on Input data 
     try 
     { 
      vault.Add(new PasswordCredential("My List", Username.Text, password.Password)); 
      Status.Text = "Status : Succeed in Registering"; 
     } 
     catch 
     { 
      Status.Text = "Status : Failed to Register"; 
     } 
    } 
} 
} 

XAML文件

<Page> 

    <!-- MainPage.xaml --> 
    <Grid> 
     <PasswordBox Name="password" HorizontalAlignment="Left" Height="118" Margin="531,197,0,0" VerticalAlignment="Top" Width="464" FontSize="52"/> 
     <TextBox Name="Username" HorizontalAlignment="Left" Height="118" Margin="531,44,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="464" FontSize="52"/> 
     <TextBlock HorizontalAlignment="Left" Height="118" Margin="10,44,0,0" TextWrapping="Wrap" Text="UserName" VerticalAlignment="Top" Width="505" FontSize="80"/> 
     <TextBlock HorizontalAlignment="Left" Height="120" Margin="10,195,0,0" TextWrapping="Wrap" Text="PassWord" VerticalAlignment="Top" Width="505" FontSize="80"/> 
     <TextBlock Name="Status" HorizontalAlignment="Left" Height="111" Margin="10,327,0,0" TextWrapping="Wrap" Text="Status " VerticalAlignment="Top" Width="1329" FontSize="60"/> 

     <Button Content="Certification" HorizontalAlignment="Left" Height="124" Margin="1006,41,0,0" VerticalAlignment="Top" Width="336" Click="Button_Click" FontSize="52"/> 

     <Button Content="Registration" HorizontalAlignment="Left" Height="124" Margin="1006,194,0,0" VerticalAlignment="Top" Width="336" Click="Button_Click_1" FontSize="52"/> 

    </Grid> 
</Page> 

詞根記憶一個 「PasswordVault」 實例

-Registar數據
2a。使用PasswordVau lt.Add方法與PasswordCredential例如
PasswordCredential實例需要3個參數
第一個參數:資源名稱(任意值)類型的字符串
第二個參數:用戶名字符串類型
第3個參數:密碼字符串類型

- 證書數據
2b.Use PasswordVault.Retribe法2paraeters
第一個參數:資源名稱(必須使用您註冊使用相同的名字)
第2個參數:用戶名
返回PasswordCredential價值
你可以得到用戶名和密碼從PasswordCredential價值

例如

//data is a PasswordCredential value 

//get Username 
string username = data.UserName; 
//get Password 
string password = data.Password 
+0

謝謝您的回答,但我不明白。是否有稱爲Windows.Security.Credentials的XAML控件? – VansFannel 2014-10-06 08:04:10

+0

再次感謝您的回答,但我不是英語或美國人,我不明白'log'的含義在這句話中:'我認爲您希望像登錄工作那樣做,不要這樣做?'謝謝。 – VansFannel 2014-10-20 14:36:37

+0

另外我不是英語母語的人。我是日本人。在日本,認證任務通常被稱爲「登錄任務」。我很抱歉讓你誤導 – 2014-10-21 08:47:21