private void LogIn() { LogInRequest request = new LogInRequest(); request.PlayerID = SystemInfo.deviceUniqueIdentifier; client.SendData((int)DataTypes.LogInRequest, request); }
//METODO DE AUTENTICACION public string Authenticate(LogInRequest request) { //CREAMOS Y DEFINIMOS LAS VARIABLES QUE FUNCIONARAN PARA CONFIGURAR LA INFORMACION DEL TOKEN A GENERAR var tokenHandler = new JwtSecurityTokenHandler(); var tokenKey = Encoding.ASCII.GetBytes(key); var tokenDescription = new SecurityTokenDescriptor { //SUBJECT: GETs OR SETs THE "ClaimsIdentity" //--------------------------------------------------------------------------------- //LA CLASE "Claims Identity" (ClaimsIdentity) ES UNA IMPLEMENTACION CONCRETA DE //LAS IDENTIDADES BASADAS EN "Claims" O "Demandas", QUE ES, UNA IDENTIDAD DESCRITA //POR UNA COLECCION DE "Claims". //--------------------------------------------------------------------------------- Subject = new System.Security.Claims.ClaimsIdentity(new Claim[] { // Los "Claims" CONTENIDOS EN UNA CLASE "ClaimsIdentity" DESCRIBEN LA ENTIDAD // CORRESPONDIENTE A LAS IDENTIDADES REPRESENTADAS, Y SON USADAS PARA TOMAR // DESICIONES DE AUTORIZACION Y DE AUTENTICACION new Claim(ClaimTypes.Name, request.Username), }), //EXPIRES: GETs OR SETs THE VALUE OF THE "expiration" claim. Expires = DateTime.UtcNow.AddHours(1), //SIGNINGCREDENTIALS: GETs OR SETs THE "SigningCredentials" USED TO CREATE //A SECURITY TOKEN. SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(tokenKey), SecurityAlgorithms.HmacSha256), }; //CREAMOS EL TOKEN CON LA CONFIGURACION PROPORCIONADA EN EL "TokenDescriptor" var token = tokenHandler.CreateToken(tokenDescription); //RETORNAMOS EL TOKEN EN FOMA DE STRING. return(tokenHandler.WriteToken(token)); }
public async Task <LogInResponse> LogInAsync(LogInRequest request, CancellationToken cancellationToken) { var messages = new List <string>(); var result = await _authRepository.LogInAsync(request.Email, request.Password, cancellationToken); if (result) { messages.Add("Logged in successfully"); var roles = await _authRepository.FindUserRolesAsync(request.Email, cancellationToken); var logInResponse = new LogInResponse { Token = GenerateJwtToken(request, roles), StatusCode = HttpStatusCode.OK, Messages = messages }; return(logInResponse); } else { messages.Add("You Email address or password is not valid. Please try again with valid credentials"); var logInResponse = new LogInResponse { StatusCode = HttpStatusCode.Unauthorized, Messages = messages }; return(logInResponse); } }
public ActionResult AsIsLogin(string usernameText, string passwordText) { LogInRequest request = new LogInRequest(usernameText, passwordText); ServiceBusResponse response = null; ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser()); if (connection == null) { response = ConnectionManager.sendLogIn(request); } else { response = connection.sendLogIn(request); } if (response.result == false) { ViewBag.AsIsResponse = "Login Failed"; return(View("Index")); } else { return(View("~/Views/Home/Index.cshtml")); } }
private string GenerateJwtToken(LogInRequest request, IList <string> roles) { var claims = new List <Claim>(); claims.Add(new Claim(ClaimTypes.Email, request.Email)); foreach (var role in roles) { claims.Add(new Claim(ClaimTypes.Role, role)); } var jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_authSettings.Key); var securityTokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(claims), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature), Expires = DateTime.UtcNow.AddMinutes(_authSettings.ExpirationInMinutes) }; var securityToken = jwtSecurityTokenHandler.CreateToken(securityTokenDescriptor); return(jwtSecurityTokenHandler.WriteToken(securityToken)); }
//This class is incomplete and should be completed by the students in milestone 2 //Hint: You will need to make use of the ServiceBusConnection class. See EchoController.cs for an example. public ActionResult Login(LogInRequest login) { //Do stuff with the new Login Info LogInRequest request = login; ServiceBusResponse response; ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser()); if (connection == null) { response = ConnectionManager.sendLogIn(request); } else { response = connection.sendLogIn(request); } ViewBag.AsIsResponse = response.response; if (response.ToString().Equals("Login Successful")) { return(View("~/Home/Index")); } else { return(View("Index")); } }
public ActionResult logIn(string username, string password) { LogInRequest request = new LogInRequest(username, password); ServiceBusResponse response = ConnectionManager.sendLogIn(request); if (response.response.Equals("")) { if (response.result) { ViewBag.LoggedInMessage = "Hello " + username + ", you have successfully logged in"; return(View("LoggedInIndex")); return(RedirectToAction("Index", "Home", new { msg = " log in sucessfull" })); } else { ViewBag.LogInResult = "Incorrect username or password!"; return(View("Index")); } } else { ViewBag.LogInResult = "Invalid log in request: " + response.response; return(View("Index")); } //ViewBag.LogInResult = response.result; }
public async override Task <LogInReply> LogIn(LogInRequest request, ServerCallContext context) { var user = _mapper.Map <User>(request); var token = await _service.LogIn(user); if (token == null) { return(new LogInReply { Code = GrpcProtoLibrary.Protos.Auth.StatusCode.Error, Role = null }); } var guidId = Guid.NewGuid().ToString(); await _client.SayGuidAsync(new HelloRequest { Guid = guidId, Role = token }); return(new LogInReply { Code = GrpcProtoLibrary.Protos.Auth.StatusCode.Success, Role = token }); }
public ActionResult LogIn(string username, string password) { LogInRequest request = new LogInRequest(username, password); ServiceBusResponse response; ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser()); if (connection == null) { response = ConnectionManager.sendLogIn(request); } else { response = connection.sendLogIn(request); } if (response.result) { ViewBag.LoginResponse = "Login Successful"; } else { ViewBag.LoginResponse = "Invalid Username or Password"; } return(View("Index")); }
public void LogIn() { Debug.Log("GuestLogin called"); LogInRequest request = new LogInRequest(); request.PID = (int)PROTOCOL.PID.LOGIN; request.PlatformType = (int)LogInRequest.PLATFORM_TYPE.GUEST; request.UserId = string.Empty; request.DeviceId = string.Empty; Http http = gameObject.AddComponent <Http>(); http.Send(request); string responseString = http.GetResponseString(); Debug.Log("GuestLogin responseString:" + responseString); LogInResponse response = JsonUtility.FromJson <LogInResponse>(responseString); if (response != null) { Debug.Log("resprotocol : " + response.ToString() + "," + response.CODE + "," + response.MSG); } }
public Result <LogInResponse> LogIn(LogInRequest request) { if (string.IsNullOrEmpty(request.Email) || string.IsNullOrEmpty(request.Password)) { return(new Result <LogInResponse>(false, "Bad request received.")); } var userResult = _accountAccessor.FindUserByEmail(request.Email); if (!userResult.IsSuccess) { return(new Result <LogInResponse>(false, "The email/password combination you entered is incorrect.")); } var password = _accountAccessor.GetUserPassword(userResult.Payload.UserID).Payload; var hashedPassword = _encryptionService.CreatePasswordHash(request.Password, password.PasswordSalt); if (hashedPassword == password.Password) { var result = _accountAccessor.CreateLogInResponse(userResult.Payload.UserID); result.Payload.CartItems = _donateService.CheckCart(userResult.Payload.UserID); return(result); } else { return(new Result <LogInResponse>(false, "The email/password combination you entered is incorrect.")); } }
public ActionResult Login(string usernameData, string passwordData) { string username = usernameData; string password = passwordData; LogInRequest LR = new LogInRequest(username, password); ServiceBusResponse response; ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser()); if (connection == null) { response = ConnectionManager.sendLogIn(LR); } else { response = connection.sendLogIn(LR); } Response.Write("<script>alert('" + response.response + "')</script>"); return(View("../Home/Index")); }
public async Task <IActionResult> Login([FromBody] LogInRequest model) { // This doesn't count login failures towards account lockout To enable password failures // to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager.PasswordSignInAsync(model.Login, model.Password, model.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { return(Ok()); } if (result.RequiresTwoFactor) { throw new NotImplementedException(); } if (result.IsLockedOut) { throw new NotImplementedException(); } else { return(BadRequest()); } // If we got this far, something failed, redisplay form }
public async Task <IActionResult> Authentication(LogInRequest login) { var user = await _userService.AuthenticateUser(login); if (user != null) { var claims = new List <Claim> { new Claim("Id", user.Id.ToString()), new Claim("Username", user.Username), new Claim("Name", user.Name), new Claim("IsAuthor", user.IsAuthor ? "true" : "false"), new Claim(ClaimTypes.Role, user.IsAuthor ? "Admin" : "User") }; var claimsIdentity = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme); await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), new AuthenticationProperties { IsPersistent = true, ExpiresUtc = DateTime.UtcNow.AddMinutes(180) }); return(RedirectToAction("Index", "Blog")); } TempData["Error"] = "Sai tài khoản hoặc mật khẩu!"; return(RedirectToAction("LogIn", "User")); }
public LoginResponse AuthenticateAndLogIn([FromBody] LogInRequest request) { var response = new LoginResponse(); try { GoogleTokenInformation tokenInformation = _googleTokenAuthentication.VerifyToken(request.Token); if (tokenInformation.Valid == false) { response.AddError($"Server failed to verify Google credentials. Please try again.", request); return(response); } UserSession sessionInformation = _userService.LogInUser(tokenInformation); response.NewUser = sessionInformation.NewUser; response.SessionId = sessionInformation.SessionId; response.User = _userService.GetPersonFromSession(sessionInformation.SessionId.ToString()); } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", request, exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}", request); } return(response); }
public string Login(LogInRequest ObjLogInRequest) { string ConnectionString = "data source=.;" + "database=Binoy;" + "Integrated Security=true"; // string ConnectionString= "Data Source=tcp:binoyserver.database.windows.net,1433;" + "Initial Catalog=binoy;" + "User Id=Binoy;" + "Password=Malu@007;"; SqlConnection connection = new SqlConnection(ConnectionString); connection.Open(); SqlCommand command = new SqlCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = "WebsiteLoginProcedure_s2por"; command.Parameters.AddWithValue("@username", ObjLogInRequest.UserId); command.Parameters.AddWithValue("@Password", ObjLogInRequest.PassWord); command.Connection = connection; SqlDataReader Reader = command.ExecuteReader(); LogInResponse ObjLogInResponse = new LogInResponse(); if (Reader.Read()) { ObjLogInResponse.Role = Reader["Role"].ToString(); return(ObjLogInResponse.Role); } else { ObjLogInResponse.Role = "Invalid Username/Password"; return(ObjLogInResponse.Role); } }
//HTTP Get /// <summary> /// This function is called by the client on the users computer when they request to log in /// </summary> /// <param name="username">The clients username</param> /// <param name="password">The clients password</param> /// <returns>Either redirects to homepage on correct log in or returns an error message to the create account screen</returns> public ActionResult UserLogIn(string username, string password) { LogInRequest request = new LogInRequest(username, password); ServiceBusResponse response = ConnectionManager.sendLogIn(request); if (response.response.Equals("")) { if (response.result) { return(RedirectToAction("Index", "Home", new { msg = "Hello " + username + " logged in sucessfully!" })); } else { ViewBag.LogInResponse = "Invalid username or password!"; } } else { ViewBag.LogInResponse = "Invalid log in request: " + response.response; } ViewBag.LogInResult = response.result; return(View("Index")); }
public async Task <LogInResponse> AuthenticateUserAsync(LogInRequest request) { var logInContext = new LogInContext(request, this.tokenService, this.userManager, this.signInManager); var result = await logInContext.ProcessAsync(); return(result); }
public void LogIn(LogInRequest request, Action <GuestControllerResult <LogInResponse> > callback) { QueueItem item = CreateQueueItem("/client/{client-id}/guest/login?expand=profile,displayName,marketing", HttpMethod.POST, request, GuestControllerAuthenticationType.ApiKey, callback); queue.Add(item); ExecuteNextCall(); }
public ActionResult LogIn(LogInRequest data) { string account = HttpUtility.HtmlEncode(data.AdminAccount); string password = HttpUtility.HtmlEncode(data.AdminPW); var user = db.Admins.FirstOrDefault(x => x.AdminAccount == account && x.AdminPW == password); if (user != null) { var ticket = new FormsAuthenticationTicket( version: 1, name: data.AdminAccount, //可以放使用者Id issueDate: DateTime.UtcNow, //現在UTC時間 expiration: DateTime.UtcNow.AddHours(1), //Cookie有效時間=現在時間往後+1小時 isPersistent: true, // 是否要記住我 true or false userData: data.AdminAccount, //可以放使用者角色名稱 cookiePath: FormsAuthentication.FormsCookiePath); var encryptedTicket = FormsAuthentication.Encrypt(ticket); //把驗證的表單加密 var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); Response.Cookies.Add(cookie); return(Redirect("/home/Index")); } else { ModelState.AddModelError("", "帳號或密碼錯誤"); return(View()); } }
public UseCaseBaseOutput <string> Process(LogInRequest request) { User user = _UserRepository.getInformation(request.email, Security.ComputeSha256Hash(request.password)); if (user == null) { return(new UseCaseBaseOutput <string>("", StatusCodes.Status404NotFound)); } if (_UserRepository.isUserLogIn(user.id)) { return(new UseCaseBaseOutput <string>(StatusCodes.Status200OK)); } string token = Security.ComputeSha256Hash(DateTime.Now.ToString() + request.IPAddress); LogInUsers logInUsers = new LogInUsers { user_id = user.id, tokenId = token, ipAddress = request.IPAddress, loginDateTime = DateTime.Now }; _UserRepository.addToLogInUsers(logInUsers); return(new UseCaseBaseOutput <string>(token, StatusCodes.Status200OK)); }
public ActionResult Login(LogInRequest logInRequest) { if (ModelState.IsValid) { CookieManager.CreateUserCookie(logInRequest.UserName, logInRequest.Password, Response); return(RedirectToAction("search", "LoanDriver")); } }
public LogInContext(LogInRequest request, ITokenService tokenService, UserManager <UserEntity> userManager, SignInManager <UserEntity> signInManager) { this.Result = new LogInResponse(); this.Request = request; this.UserManager = userManager; this.SignInManager = signInManager; this.TokenService = tokenService; }
public string BankLogIn(LogInRequest ObjLogInRequest) { LogInServiceMethod ObjLogInServiceMethod = new LogInServiceMethod(); string Role = ObjLogInServiceMethod.Login(ObjLogInRequest); return(Role); }
public void RaisePacketReceived(ServerConnectionBase serverConnection) { var l = new LogInRequest { Email = "[email protected]", Password = "******" }; var bp = BinaryProtocol.FromData(l, new ProtoBufGenericSerializer <LogInRequest>()); _serverTransport.RaiseReceive(typeof(LogInRequest), bp.GetDataToSend(), serverConnection); }
public Login() { _request = new LogInRequest { Login = "******", Password = "******", RememberMe = true }; }
public static async Task Main(string[] args) { const string Host = "localhost"; const int Port = 16842; var channel = new Channel($"{Host}:{Port}", ChannelCredentials.Insecure); var client = new LogInRequest(); Console.WriteLine("------------------------------------"); Console.WriteLine("----------- Hello there ! ----------"); Console.WriteLine("------------------------------------"); do { Console.WriteLine("\nPlease enter your name: "); client.Name = Console.ReadLine(); Console.WriteLine("\n------------------------------------"); } while (isValid(client.Name) == false); var logIn = new LogInService.LogInServiceClient(channel); logIn.logIn(client); Console.WriteLine("Welcome " + client.Name + "!"); Console.WriteLine("------------------------------------"); var clientMessage = new ChatRequest(); clientMessage.Name = client.Name; do { do { Console.WriteLine("\nPlease enter your message: "); clientMessage.Textmessage = Console.ReadLine(); Console.WriteLine("------------------------------------"); } while (isValid(clientMessage.Textmessage) == false); var chat = new ChatService.ChatServiceClient(channel); chat.sendMessage(clientMessage); var stream = chat.chatStream(); while (await stream.ResponseStream.MoveNext()) { var serverMessage = stream.ResponseStream.Current; Console.WriteLine(serverMessage.Name + " says: " + serverMessage.Textmessage); Console.WriteLine("------------------------------------"); } } while (true); // Shutdown channel.ShutdownAsync().Wait(); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
/// <summary> /// Log-In Async. /// </summary> /// <param name="request">The <see cref="LogInRequest"/>.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> /// <returns>The <see cref="AccessToken"/>.</returns> public virtual async Task <AccessToken> LogInAsync(LogInRequest request, CancellationToken cancellationToken = default) { if (request == null) { throw new ArgumentNullException(nameof(request)); } return(await this.CustomAsync <LogInRequest, AccessToken>(request, cancellationToken)); }
public static void login(LogInRequest logInRequest) { MobileUsersService mobileUsersService = new MobileUsersService(); mobileUsersService.logIn(logInRequest, (TokenObject tokenObject) => { Debug.Log("successful " + "login: "******"failure " + "login:" + resultCode); }); }
private LogInResponse GetLogInResponse(LogInRequest request, string ipAddress, ResponseCode responseCode, Exception ex) { LogFailedLogin(request, ipAddress, ex); return(new LogInResponse { Code = responseCode, ErrorMessage = ex.Message }); }