Membership.EnablePasswordRetrieval プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Membership.EnablePasswordRetrieval プロパティの意味・解説 

Membership.EnablePasswordRetrieval プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

現在のメンバシップ プロバイダによってユーザーパスワード取得許可されているかどうかを示す値を取得します

名前空間: System.Web.Security
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Shared ReadOnly Property
 EnablePasswordRetrieval As Boolean
Dim value As Boolean

value = Membership.EnablePasswordRetrieval
public static bool EnablePasswordRetrieval
 { get; }
public:
static property bool EnablePasswordRetrieval
 {
    bool get ();
}
/** @property */
public static boolean get_EnablePasswordRetrieval
 ()
public static function get
 EnablePasswordRetrieval () : boolean

プロパティ
メンバシップ プロバイダパスワード取得サポートしている場合trueそれ以外場合false

解説解説
使用例使用例

次のコード例に、ASP.NET アプリケーションの Web.config ファイルsystem.web セクションmembership 要素示します。この例では、アプリケーションが SqlMembershipProvider のインスタンス使用するように指定しパスワードリセット有効化ます。

<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="20">
  <providers>
    <add name="SqlProvider"
      type="System.Web.Security.SqlMembershipProvider"
      connectionStringName="SqlServices"
      enablePasswordRetrieval="true"
      enablePasswordReset="false"
      requiresQuestionAndAnswer="false"
      passwordFormat="Encrypted"
      applicationName="MyApplication" />
  </providers>
</membership>

まず EnablePasswordRetrievaltrue であることを確認し次に指定したユーザー名パスワード取得し指定したユーザー電子メール アドレスパスワード送信するコード例次に示します

メモメモ

高水準セキュリティ求められるサイトでは、パスワードクリア テキスト電子メール使って返信することは避けてください高いセキュリティ要求されるサイトでは、SSL などの暗号化使用してパスワード返すことをお勧めます。

<%@ Page Language="VB" %>

<%@ Import Namespace="System.Web.Security"
 %>
<%@ Import Namespace="System.Net.Mail"
 %>

<script runat="server">

  Public Sub Page_Load(ByVal
 sender As Object, ByVal
 args As EventArgs)

    If Not Membership.EnablePasswordRetrieval
 Then
      FormsAuthentication.RedirectToLoginPage()
    End If

    Msg.Text = ""

    If Not IsPostBack Then
      Msg.Text = "Please enter a user name."
    Else
      VerifyUsername()
    End If

  End Sub


  Private Sub VerifyUsername()

    Dim user As MembershipUser = Membership.GetUser(UsernameTextBox.Text,
 False)

    If user Is Nothing Then
      Msg.Text = "The user name " & Server.HtmlEncode(UsernameTextBox.Text)
 & " was not found. Please check the value and re-enter."

      QuestionLabel.Text = ""
      QuestionLabel.Enabled = False
      AnswerTextBox.Enabled = False
      EmailPasswordButton.Enabled = False
    Else
      QuestionLabel.Text = user.PasswordQuestion
      QuestionLabel.Enabled = True
      AnswerTextBox.Enabled = True
      EmailPasswordButton.Enabled = True
    End If

  End Sub


  Public Sub EmailPassword_OnClick(ByVal
 sender As Object, ByVal
 args As EventArgs)

    ' Note: Returning a password in clear text using e-mail is not recommended
 for
    ' sites that require a high level of security.

    Try
      Dim password As String
 = Membership.Provider.GetPassword(UsernameTextBox.Text, AnswerTextBox.Text)
      Dim u As MembershipUser = Membership.GetUser(UsernameTextBox.Text)
      EmailPassword(u.Email, password)
      Msg.Text = "Your password was sent via e-mail."
    Catch e As MembershipPasswordException
      Msg.Text = "The password answer is incorrect. Please check
 the value and try again."
    Catch e As System.Configuration.Provider.ProviderException
      Msg.Text = "An error occurred retrieving your password.
 Please check your values " & _
                 "and try again."
    End Try

  End Sub


  Private Sub EmailPassword(ByVal
 email As String, ByVal
 password As String)

    Try
      Dim Message As MailMessage = New
 MailMessage("administrator", email)
      Message.Subject = "Your Password"
      Message.Body = "Your password is: " & Server.HtmlEncode(password)
      
      Dim SmtpMail As SmtpClient = New
 SmtpClient("SMTPSERVER")
      SmtpMail.Send(Message)
    Catch
      Msg.Text = "An exception occurred while sending your password.
 Please try again."
    End Try

  End Sub

</script>

<html>
<head>
  <title>Sample: Retrieve Password</title>
</head>
<body>
  <form runat="server">
    <h3>
      Retrieve Password</h3>
    <asp:Label ID="Msg" runat="server"
 ForeColor="maroon" /><br>
    Username:
    <asp:TextBox ID="UsernameTextBox" Columns="30"
 runat="server" AutoPostBack="True"
 />
    <asp:RequiredFieldValidator ID="UsernameRequiredValidator"
 runat="server" ControlToValidate="UsernameTextBox"
      ForeColor="red" Display="Static"
 ErrorMessage="Required" /><br>
    Password Question: <b>
      <asp:Label ID="QuestionLabel" runat="server"
 /></b><br>
    Answer:
    <asp:TextBox ID="AnswerTextBox" Columns="60"
 runat="server" Enabled="False"
 />
    <asp:RequiredFieldValidator ID="AnswerRequiredValidator"
 runat="server" ControlToValidate="AnswerTextBox"
      ForeColor="red" Display="Static"
 ErrorMessage="Required" Enabled="False"
 /><br>
    <asp:Button ID="EmailPasswordButton" Text="Email
 My Password" OnClick="EmailPassword_OnClick"
      runat="server" Enabled="False"
 />
  </form>
</body>
</html>
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Net.Mail" %>
<script runat="server">

public void Page_Load(object sender, EventArgs
 args)
{
  if (!Membership.EnablePasswordRetrieval)
  {
    FormsAuthentication.RedirectToLoginPage();
  }

  Msg.Text = "";

  if (!IsPostBack)
  {
    Msg.Text = "Please enter a user name.";
  }
  else
  {
    VerifyUsername();
  }
}


public void VerifyUsername()
{
    MembershipUser user = Membership.GetUser(UsernameTextBox.Text, false);

    if (user == null)
    {
      Msg.Text = "The user name " + Server.HtmlEncode(UsernameTextBox.Text)
 + " was not found. Please check the value and re-enter.";

      QuestionLabel.Text = "";
      QuestionLabel.Enabled = false;
      AnswerTextBox.Enabled = false;
      EmailPasswordButton.Enabled = false;
    }
    else
    {
      QuestionLabel.Text = user.PasswordQuestion;
      QuestionLabel.Enabled = true;
      AnswerTextBox.Enabled = true;
      EmailPasswordButton.Enabled = true;
    }
}


public void EmailPassword_OnClick(object sender,
 EventArgs args)
{
  // Note: Returning a password in clear text using e-mail is not recommended
 for
  // sites that require a high level of security.

  try
  {
    string password = Membership.Provider.GetPassword(UsernameTextBox.Text,
 AnswerTextBox.Text);
    MembershipUser u = Membership.GetUser(UsernameTextBox.Text);
    EmailPassword(u.Email, password);
    Msg.Text = "Your password was sent via e-mail.";
  }
  catch (MembershipPasswordException e)
  {
    Msg.Text = "The password answer is incorrect. Please check the value and
 try again.";
  }
  catch (System.Configuration.Provider.ProviderException e)
  {
    Msg.Text = "An error occurred retrieving your password. Please check your
 values " +
               "and try again.";
  }
}


private void EmailPassword(string
 email, string password)
{
  try
  {
    MailMessage Message = new MailMessage("administrator",
 email);
    Message.Subject = "Your Password";
    Message.Body = "Your password is: " + Server.HtmlEncode(password);

    SmtpClient SmtpMail = new SmtpClient("SMTPSERVER");
    SmtpMail.Send(Message);
  }
  catch 
  {
    Msg.Text = "An exception occurred while sending your
 password. Please try again.";
  }
}

</script>
<html>
<head>
<title>Sample: Retrieve Password</title>
</head>
<body>

<form runat="server">
  <h3>Retrieve Password</h3>

  <asp:Label id="Msg" runat="server" ForeColor="maroon"
 /><BR>

  Username: <asp:Textbox id="UsernameTextBox" Columns="30"
 runat="server" AutoPostBack="true" />
            <asp:RequiredFieldValidator id="UsernameRequiredValidator"
 runat="server"
                                        ControlToValidate="UsernameTextBox"
 ForeColor="red"
                                        Display="Static" ErrorMessage="Required"
 /><BR>

  Password Question: <B><asp:Label id="QuestionLabel" runat="server"
 /></B><BR>

  Answer: <asp:TextBox id="AnswerTextBox" Columns="60" runat="server"
 Enabled="false" />
          <asp:RequiredFieldValidator id="AnswerRequiredValidator" runat="server"
                                      ControlToValidate="AnswerTextBox"
 ForeColor="red"
                                      Display="Static" ErrorMessage="Required"
 Enabled="false" /><BR>

  <asp:Button id="EmailPasswordButton" Text="Email My Password"
 
              OnClick="EmailPassword_OnClick" runat="server"
 Enabled="false" />

</form>

</body>
</html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Membership.EnablePasswordRetrieval プロパティ」の関連用語

Membership.EnablePasswordRetrieval プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Membership.EnablePasswordRetrieval プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS