} // CanExecuteOk #endregion #region METHODS /// <summary> /// /// </summary> /// <remarks> /// Sin comentarios adicionales /// </remarks> public void ExecuteOk() { ApplicationContext.UserContext = new UserContextDto(); this.DialogResult = true; try { AuthenticationServiceClient loginSvc = new AuthenticationServiceClient(); int applicationId = 2; if (ConfigurationManager.AppSettings.AllKeys.Contains("applicationId")) { applicationId = int.Parse(ConfigurationManager.AppSettings["applicationId"]); } UserContextDto userContext = loginSvc.Login(new UserCredentialsDto(this.Login, this.Password, string.Empty, applicationId, string.Empty)); if (userContext != null) { ApplicationContext.UserContext = userContext; this.DialogResult = true; } else { this.DialogResult = false; } } catch (System.Exception ex) { this.DialogResult = false; } } // ExecuteOk
public void GetMapsTest() { // arrange var authenticatioProxy = new AuthenticationServiceClient(); var sessionId = authenticatioProxy.Login("editor", "editor", Role.Editor); var mapEditorProxy = new MapEditorServiceClient(sessionId); // act var maps = mapEditorProxy.GetMaps().ToList(); // asset Assert.IsTrue(maps.Count > 1); Assert.IsTrue(maps.First().Windows.Count == 1); Assert.IsTrue(maps.First().Windows.First().Holes.Count == 3); }
public bool Login(string username, string password, string customCredential, bool isPersistent) { AuthenticationServiceClient proxy = new AuthenticationServiceClient(); using (new OperationContextScope(proxy.InnerChannel)) { bool result = proxy.Login(username, password, customCredential, isPersistent); var responseMessageProperty = (HttpResponseMessageProperty) OperationContext.Current.IncomingMessageProperties[HttpResponseMessageProperty.Name]; if (result) { HttpContext.Current.Session["cookieHolder"] = responseMessageProperty.Headers.Get("Set-Cookie"); } return result; } }
private void button1_Click(object sender, EventArgs e) { IsLoggedIn = AuthClient.Login(textBox1.Text, textBox2.Text); if (IsLoggedIn) { client.ClientCredentials.UserName.UserName = textBox1.Text; client.ClientCredentials.UserName.Password = textBox2.Text; PlayerCredentials.Instance.Player = client.RetrievePlayer(textBox1.Text); this.Hide(); (new JoinGame(client)).Show(); } else { MessageBox.Show("Error logging in! User name or password was incorrect", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Login(string username, string password) { bool result = false; AuthenticationServiceClient client = new AuthenticationServiceClient(); OperationContextScope scope = new OperationContextScope(client.InnerChannel); try { result = client.Login(username, password, null, false); MessageProperties props = OperationContext.Current.IncomingMessageProperties; HttpResponseMessageProperty prop = props[HttpResponseMessageProperty.Name] as HttpResponseMessageProperty; string rawCookies = prop.Headers[HttpResponseHeader.SetCookie]; if (!result) { ONyRFaultException e = new ONyRFaultException(); e.ErrorCode = (int)ErrorCode.InvalidCredentialsError; throw new FaultException <ONyRFaultException>(e); } mResponder.LoginResult(FormatCookie(rawCookies)); } catch (FaultException <ONyRFaultException> ex) { mResponder.LoginFault((ErrorCode)ex.Detail.ErrorCode); } catch (Exception) { mResponder.LoginFault(ErrorCode.NonONyRError); } finally { if (client != null) { client.Close(); } } }
public async Task <ActionResult> Login(LoginViewModel model) { if (!ModelState.IsValid) { model.HasErrors = true; return(this.View(model)); } try { await Tracer.Info("Trying to login"); var proxy = new AuthenticationServiceClient(); var sessionId = proxy.Login(model.Username, model.Password, Role.Administrator); AuthenticationHelper.SessionId = sessionId; var returnUrl = Request.QueryString["ReturnUrl"]; if (!string.IsNullOrWhiteSpace(returnUrl)) { return(this.Redirect(returnUrl)); } return(this.RedirectToAction("Index", "Home")); } catch (FaultException <LoginFailedException> ex) { ModelState.AddModelError(string.Empty, Resources.Global.LoginFailed); model.HasErrors = true; this.HandleException("Login failed", ex); } catch (Exception ex) { ModelState.AddModelError(string.Empty, Resources.Global.ErrorOccurredInline); model.HasErrors = true; this.HandleException("Error while trying to login", ex); } return(this.View(model)); }
public MyServiceTst(string[] args) { if (args.Length == 3) { // The host address was passed in, so that is used. _Host = args[2]; } else { _Host = "localhost:8080"; } string username = args[0]; string password = args[1]; string endPtAddr = strEndPtAddr("MyAuthenticationSvcWrap"); Console.WriteLine("Attempting to connect as username = "******"\n password length = " + password.Length.ToString() + "\n on server " + _Host + "\n" + "\n" + "End point address: " + endPtAddr ); // BasicHttpBinding and endpoint are explicitly passed and ignored // in th app.config file. BasicHttpBinding binding = new BasicHttpBinding(); AuthenticationServiceClient authService = new AuthenticationServiceClient(binding, new EndpointAddress(endPtAddr)); CookieContainer cookieContainer; string customCredential = "Not used by the default membership provider."; // Authentication ticket remains valid across sessions. bool isPersistent = true; bool bLogin = false; using (new OperationContextScope(authService.InnerChannel)) { try { bLogin = authService.Login(username, password, customCredential, isPersistent); cookieContainer = GetCookies(OperationContext.Current); } catch (EndpointNotFoundException enfe) { Console.WriteLine(enfe.Message); if (enfe.InnerException != null && enfe.InnerException.Message != null) { Console.WriteLine(enfe.InnerException.Message); } return; } } if (bLogin) { Console.WriteLine("Welcome, " + username + ". You are now logged in."); GetUserRoles(cookieContainer); GetProfileInfo(cookieContainer); } else { Console.WriteLine("Credentials could not be validated."); } }
private void OnLogin() { string userName = Request.Form["txtUserName"]; string psw = Request.Form["txtPsw"]; string sVc = Request.Form["txtVc"]; if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(psw)) { MessageBox.Messager(this.Page, Page.Controls[0], "用户名或密码输入不能为空!", MessageContent.AlertTitle_Error, "error"); return; } if (string.IsNullOrWhiteSpace(sVc)) { MessageBox.Messager(this.Page, Page.Controls[0], "验证码输入不能为空!", MessageContent.AlertTitle_Error, "error"); return; } bool isRemember = Request.Form["cbRememberMe"] == "1" ? true : false; userName = userName.Trim(); psw = psw.Trim(); sVc = sVc.Trim(); var cookie = Request.Cookies["LoginVc"]; if (cookie == null || string.IsNullOrWhiteSpace(cookie.Value)) { MessageBox.Messager(this.Page, Page.Controls[0], "验证码不存在或已过期!", MessageContent.AlertTitle_Error, "error"); return; } string validCode = cookie.Value; AESEncrypt aes = new AESEncrypt(); if (sVc.ToLower() != aes.DecryptString(validCode).ToLower()) { MessageBox.Messager(this.Page, Page.Controls[0], "验证码输入不正确,请检查!", MessageContent.AlertTitle_Error, "error"); return; } AuthenticationServiceClient authServiceClient = new AuthenticationServiceClient(); if (!authServiceClient.Login(userName, psw, "", true)) { MessageBox.Messager(this.Page, Page.Controls[0], "用户名或密码有误,请正确输入!", MessageContent.AlertTitle_Error, "error"); return; } #region 已废弃 使用身份认证服务代替 //string userData = string.Empty; //MembershipUser userInfo = Membership.GetUser(userName); //if (!Membership.ValidateUser(userName, psw)) //{ // if (userInfo == null) // { // MessageBox.Messager(this.Page, Page.Controls[0], "用户名不存在!", MessageContent.AlertTitle_Sys_Info); // return; // } // if (userInfo.IsLockedOut) // { // MessageBox.Messager(this.Page, Page.Controls[0], "您的账号已被锁定,请联系管理员先解锁后才能登录!", MessageContent.AlertTitle_Sys_Info); // return; // } // if (!userInfo.IsApproved) // { // MessageBox.Messager(this.Page, Page.Controls[0], "您的帐户尚未获得批准。您无法登录,直到管理员批准您的帐户!", MessageContent.AlertTitle_Sys_Info); // return; // } // else // { // MessageBox.Messager(this.Page, Page.Controls[0], "密码不正确,请检查!", MessageContent.AlertTitle_Sys_Info); // return; // } //} //userData = userInfo.ProviderUserKey.ToString(); //登录成功,则 //bool isPersistent = true; //bool isRemember = true; //bool isAuto = false; //double d = 100; //if (cbRememberMe.Checked) isAuto = true; //自动登录 设置时间为7天 //if (isAuto) d = 10080; ////创建票证 //FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(d), // isPersistent, userData, FormsAuthentication.FormsCookiePath); ////加密票证 //string encTicket = FormsAuthentication.Encrypt(ticket); ////创建cookie //Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); #endregion if (isRemember) { Response.Cookies["UserInfo"]["UserName"] = aes.EncryptString(userName); Response.Cookies["UserInfo"].Expires = DateTime.Now.AddDays(7); } else { if (Request.Cookies["UserInfo"] != null) { Response.Cookies["UserInfo"].Expires = DateTime.Now.AddMinutes(-5); } } FormsAuthentication.RedirectFromLoginPage(userName, false);//使用此行会清空ticket中的userData ?!!! //Response.Redirect(FormsAuthentication.GetRedirectUrl(userName, isPersistent)); }