HashPassword(Password: String): String;
HashPassword(System.String): System.String;
Password. Password that must be hashed.
The HashPassword method hashes the password.
Executing the example requires the following components on the form: Button, EditBox (for the Fore.NET example use the TextBox component), Memo (for the Fore.NET example use the ListBox component) named Button1, EditBox1/textBox1, Memo1/listBox1 correspondingly.
Add system assemblies:
For Fore example: Metabase, Collections, Forms.
For Fore.NET example: Metabase, Forms.Net, ForeSystem.
The example is a handler of the OnClick event for the Button1 component.
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
MB: IMetabase;
MS: IMetabaseSecurity;
User: IMetabaseUser;
HashP: String;
MbPassHistory: IPasswordHistory;
Lic: Object;
Begin
MB := MetabaseClass.Active;
// Get license to work with security manager
Lic := Mb.RequestLicense(UiLicenseFeatureType.Adm);
MS := MB.Security;
// Get parameters of the ADMIN user
User := MS.ResolveName("ADMIN") As IMetabaseUser;
HashP := MS.HashPassword(EditBox1.Text);
MbPassHistory := User.PasswordHistory;
// Add the specified password to the history
If MbPassHistory.Contains(HashP) Then
Memo1.Lines.Add("Password '" + EditBox1.Text + "' is already in hystory");
Else MbPassHistory.Insert(HashP);
Memo1.Lines.Add("Password '" + EditBox1.Text + "' is added to the history");
End If;
// Save changes
MS.Apply;
// Check in license
Lic := Null;
End Sub Button1OnClick;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Forms.Net;
Imports Prognoz.Platform.Interop.ForeSystem;
…
Private Sub button1_Click(sender: System.Object; e: System.EventArgs);
Var
MB: IMetabase;
MS: IMetabaseSecurity;
User: IMetabaseUser;
HashP: String;
MbPassHistory: IPasswordHistory;
Lic: Object;
Begin
MB := Self.Metabase;
// Get license to work with security manager
Lic := Mb.RequestLicense(UiLicenseFeatureType.lftAdm);
MS := MB.Security;
// Get parameters of the ADMIN user
User := MS.ResolveName("ADMIN") As IMetabaseUser;
HashP := MS.HashPassword(textBox1.Text);
MbPassHistory := User.PasswordHistory;
// Add the specified password to the history
If MbPassHistory.Contains(HashP) Then
listBox1.Items.Add("Password '" + textBox1.Text + "' is already in history");
Else MbPassHistory.Insert(HashP);
listBox1.Items.Add("Password '" + textBox1.Text + "' is added to the history");
End If;
// Save changes
MS.Apply();
// Check in license
Lic := Null;
End Sub;
After executing the example, the Memo/ListBox component displays the result of checking the specified password in the EditBox/TextBox component:
If password is absent in password history, it will be added.
If password is present in password history, the corresponding message will be displayed.
See also: