O2 Script/Ask user for security credentials (Username and Password)
From
this script (Windows Forms Control) is a small pop-up window that asks the user for its a credential (username and password).
The returned data is of type ICredential (used in O2 to access security credentials)
screenshots
- in O2's Simple Script Editor enter the following code
return ascx_AskUserForLoginDetails.ask(); //O2File:C:\O2\_XRules_Local\ascx_AskUserForLoginDetails.cs
- and click execute
- enter some values on the username and password field
- which you can see are now loaded into a ICredential object (show in the 'Ouput' window of O2's Simple Script Editor)
source code
public class ascx_AskUserForLoginDetails : ContainerControl { public string UserName { get;set;} public string Password { get;set;} public AutoResetEvent HaveAnswer { get;set;} public TextBox UserNameTextBox { get; set;} public TextBox PasswordTextBox { get; set;} public Button OKButton { get; set;} public static ICredential ask() { var loginDetailsGui = O2Gui.open<ascx_AskUserForLoginDetails>("Enter Login Details", 250,115); loginDetailsGui.buildGui(); var credential = loginDetailsGui.getAnswer(); loginDetailsGui.close(); return credential; } public ascx_AskUserForLoginDetails() { HaveAnswer = new AutoResetEvent(false); UserName = ""; Password = ""; } public void buildGui() { UserNameTextBox = this.add_Label("Username:",10,0) .append_TextBox(""); UserNameTextBox.onTextChange((text)=> UserName = text) .align_Right(this); PasswordTextBox = this.add_Label("Password: ",35,0) .append_TextBox(""); PasswordTextBox.onTextChange((text)=> Password = text) .align_Right(this); var OKButton = this.add_Button("OK", 60,0); OKButton.onClick(answerAvailable) .left(this.width() - OKButton.width() - 1) .anchor_BottomRight(); this.parentForm().Closed += (sender,e) => answerAvailable(); } public ICredential getAnswer() { HaveAnswer.WaitOne(); var credential = new Credential(); credential.UserName = UserName; credential.Password = Password; "u:{0}".debug(credential.UserName); "p:{0}".debug(credential.Password); return credential; } public void answerAvailable() { HaveAnswer.Set(); } public void close() { if (this.parentForm() != null) this.parentForm().Close(); } }




