public void SisseLogimine(string Login, string Password)
        {
            using (LoginDbContext _context = new LoginDbContext())
            {
                var name = _context.LoginTable.FirstOrDefault(u => u.Name == Login);

                if (!string.IsNullOrEmpty(Login) || !string.IsNullOrEmpty(Password))
                {
                    if (name != null)
                    {
                        string hashedpassword = GenerateSHA256Hash(Password, name.Salt);
                        if (name.Hash == hashedpassword)
                        {
                            _service.MessageInfo("Sisse logitud!", "Info");
                        }
                        else
                        {
                            _service.MessageError("Vale parool!", "Viga");
                        }
                    }
                    else
                    {
                        _service.MessageError("Sellist kasutajad " + Login + " ei ole olemas!", "Viga");
                    }
                }
                else
                {
                    _service.MessageExclamation("Sisestage andmed!", "Sõnum");
                }
            }
        }
 public void Registreerimine(string Login, string Password)
 {
     using (LoginDbContext _context = new LoginDbContext())
     {
         LoginTable loginTable = new LoginTable()
         {
             Name = Login
         };
         if (!string.IsNullOrEmpty(Login) || !string.IsNullOrEmpty(Password))
         {
             string _salt = CreateSalt(10);
             loginTable.Salt = _salt;
             loginTable.Hash = GenerateSHA256Hash(Password, _salt);
             try
             {
                 _context.LoginTable.Add(loginTable);
                 _context.SaveChanges();
                 _service.MessageInfo("Registreeritud", "Info");
             }
             catch (Exception ex)
             {
                 _service.MessageError(ex.Message, "Viga");
             }
         }
         else
         {
             _service.MessageExclamation("Sisestage andmed!", "Sõnum");
         }
     }
 }
 public SecurityController(UserManager <AppUser> userManager, SignInManager <AppUser> signInManager, LoginDbContext context, IConfiguration configuration)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _context       = context;
     _configuration = configuration;
 }
Example #4
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, LoginDbContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    await context.Response.WriteAsync("Hello Login!");
                });
                endpoints.MapControllers();
            });

            dbContext.Database.Migrate();

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Login API");
            });
        }
Example #5
0
        // GET: Login
        public ActionResult Index()
        {
            LoginDbContext    db            = new LoginDbContext();
            List <LoginModel> lstLoginModel = db.LoginModel.ToList();

            return(View(lstLoginModel));
        }
Example #6
0
 public RegistrationService(
     LoginDbContext context,
     UserManager <User> userManager)
 {
     _context     = context;
     _userManager = userManager;
 }
Example #7
0
 // GET: Account
 public ActionResult Index()
 {
     using (LoginDbContext db = new LoginDbContext())
     {
         return(View(db.UserAccount.ToList()));
     }
 }
 //Constructeur du controleur
 public HomeController(IConfiguration iConfig, UserManager <LoginUser> userManager, LoginDbContext log)
 {
     this.config       = iConfig;
     this.contexteActu = new ActualisationContext(config.GetConnectionString("DefaultConnection"));
     this._userManager = userManager;
     this.contextLogin = log;
 }
Example #9
0
 public static void InitDbContext(ModelBuilder modelBuilder)
 {
     modelBuilder.Ignore <User>().Ignore <Group>().Ignore <DevicePlatform>();
     LoginDbContext.InitDbContext(modelBuilder, false);
     DeviceDbContext.InitDbContext(modelBuilder, false);
     modelBuilder.Entity <LoginDevices>().HasOne(x => x.LdLogin);
     modelBuilder.Entity <LoginDevices>().HasOne(x => x.LdDevice);
 }
Example #10
0
        public UnitOfWorkLogin(LoginDbContext loginDbContext)
        {
            m_dbContext = loginDbContext;

            CompanyManager = new RepositoryCompanyManager(m_dbContext);
            MemberStudent  = new RepositoryMemberStudent(m_dbContext);
            SystemManager  = new RepositorySystemManager(m_dbContext);
        }
 public static void InitDbContext(ModelBuilder modelBuilder)
 {
     modelBuilder.Ignore <DevicePlatform>().Ignore <User>();
     PolicyDbContext.InitDbContext(modelBuilder, false);
     LoginDbContext.InitDbContext(modelBuilder, false);
     GroupDbContext.InitDbContext(modelBuilder);
     modelBuilder.Entity <PolicySet>().HasOne(x => x.PolicySetPolicy);
     modelBuilder.Entity <PolicySet>().HasOne(x => x.UserLogin);
     modelBuilder.Entity <PolicySet>().HasOne(x => x.PolicySetGroup);
 }
Example #12
0
 public LoginDbContextSeed(
     LoginDbContext context,
     IEventBus eventBus,
     ILogger <LoginDbContextSeed> logger)
 {
     _passwordHasher = new PasswordHasher <User>();
     _logger         = logger;
     _context        = context;
     _eventBus       = eventBus;
 }
Example #13
0
 public UserController(
     UserManager <User> userManager,
     IEventBus eventBus,
     LoginDbContext context,
     LoginDbContextSeed seeder)
 {
     _userManager = userManager;
     _eventBus    = eventBus;
     _context     = context;
     _seeder      = seeder;
 }
 public LoginController(UserManager <LoginUser> userManager, RoleManager <LoginRole> roleManager,
                        SignInManager <LoginUser> signInManager, ILogger <LoginController> logger, ActualisationContext cont,
                        LoginDbContext log
                        )
 {
     _userManager      = userManager;
     _roleManager      = roleManager;
     _signInManager    = signInManager;
     _logger           = logger;
     this.context      = cont;
     this.contextLogin = log;
 }
Example #15
0
 public LoginModel(SignInManager <User> signInManager,
                   ILogger <LoginModel> logger,
                   UserManager <User> userManager,
                   IEmailSender emailSender,
                   LoginDbContext context
                   )
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _emailSender   = emailSender;
     _logger        = logger;
     _context       = context;
 }
 public string ValidateUser(string userName)
 {
     using (LoginDbContext db = new LoginDbContext())
     {
         //如果当前用户名 已经存在 返回false
         if (db.UserRegisters.Where(a => a.UserName == userName).Count() > 0)
         {
             return("false");
         }
         else
         {
             return("ok");
         }
     }
 }
Example #17
0
 /// <summary>
 /// 获取密码 V2.0
 /// </summary>
 /// <param name="loginName"></param>
 /// <returns></returns>
 public string GetUserPassword(string loginName)
 {
     using (LoginDbContext db = new LoginDbContext())
     {
         var user = db.LoginModel.Where(o => o.UserName.ToLower().Equals(loginName));
         if (user.Any())
         {
             return(user.FirstOrDefault().Password);
         }
         else
         {
             return(string.Empty);
         }
     }
 }
Example #18
0
 public ActionResult Register(UserAccount account)
 {
     if (ModelState.IsValid)
     {
         using (LoginDbContext db = new LoginDbContext())
         {
             db.UserAccount.Add(account);
             db.SaveChanges();
         }
         // for clear the context of all input controls
         ModelState.Clear();
         ViewBag.Message = account.FirstName + " " + account.LastName + " successfully registered.";
     }
     return(View());
 }
Example #19
0
        public ActionResult TestAdd([Bind(Include = "UserName,Password,IsActive,UserId")] LoginModel model)   //没有Bind进来的字段就添加不进去数据库,
        {
            LoginDbContext db = new LoginDbContext();

            LoginModel loginModel = new LoginModel()
            {
                UserId   = model.UserId, //userID设置为了Key,既主键,EF会自动增长,这里添加的话,也不会报错。如果有UserID为1的记录我在添加也不会报错。加进去是递增的,是EF自动增长决定的,和模型绑定无关。
                UserName = model.UserName,
                Password = model.Password,
                IsActive = model.IsActive
            };

            db.LoginModel.Add(loginModel);
            db.SaveChanges();
            return(RedirectToAction("Login"));
        }
 public JsonResult Register(UserRegister model)
 {
     using (LoginDbContext db = new LoginDbContext())
     {
         if (db.UserRegisters.Where(a => (a.UserName == model.UserName)).Count() > 0)
         {
             return(Json(new { result = "error", content = "注册失败,用户名已经存在" }));
         }
         if (db.UserRegisters.Where(a => a.UserEmail == model.UserEmail).Count() > 0)
         {
             return(Json(new { result = "error", content = "注册失败,邮箱已经存在" }));
         }
         db.UserRegisters.Add(model);
         db.SaveChanges();
         return(Json(new { result = "success", content = "注册成功 欢迎你:" + model.UserName }));
     }
 }
Example #21
0
 public ActionResult AddOrEdit(User user, LoginDbContext loginDbContext)
 {
     using (loginDbContext)
     {
         if (user.UserName.Any(x => user.UserName == user.UserName))
         {
             ViewBag.DuplicateMessage = "User Name Already Exists.";
             return(View("SignUp", user));
         }
         else
         {
         }
     }
     ModelState.Clear();
     @ViewBag.SuccessMessage = "Registration Successful.";
     return(View("SignUp", new User()));
 }
Example #22
0
 public ActionResult Login(UserAccount user)
 {
     using (LoginDbContext db = new LoginDbContext())
     {
         var usr = db.UserAccount.Where(u => u.Username == user.Username && u.Password == user.Password).FirstOrDefault();
         if (usr != null)
         {
             Session["UserID"]   = usr.UserID.ToString();
             Session["Username"] = usr.Username.ToString();
             return(RedirectToAction("LoggedIn"));
         }
         else
         {
             ModelState.AddModelError("", "Username or Password is wrong.");
         }
     }
     return(View());
 }
        public ActionResult Login(string username, string password)
        {
            try
            {
                using (var db = new LoginDbContext())
                {
                    User user = db.Users.Where(s => s.UserName == username || s.EmailId == username).FirstOrDefault();
                    if (user != null)
                    {
                        //获取登陆用户存在数据库中的盐
                        var hashCode = user.VCode;
                        //获取登陆用户加密的密码
                        var encodingPasswordString = EncryptionHelper.EncodePassword(password, hashCode);
                        //Check Login Detail User Name Or Password

                        var query = (from s in db.Users where (s.UserName == username || s.EmailId == username) && s.Password.Equals(encodingPasswordString) select s).FirstOrDefault();
                        if (query != null)
                        {
                            //RedirectToAction("Details/" + id.ToString(), "FullTimeEmployees");
                            //return View("../Admin/Registration"); url not change in browser
                            Session["UserName"] = query.UserName.ToString();

                            return(RedirectToAction("Index", "Login"));
                        }
                        else
                        {
                            ViewBag.ErrorMessage = "Invallid User Name or Password";
                            return(View());
                        }
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "Invallid User Name or Password";
                        return(View());
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = " Error!!! contact [email protected]";
                return(View());
            }
        }
Example #24
0
        public void Execute(object parameter)
        {
            Hashing        hash    = new Hashing();
            LoginDbContext dbUser  = new LoginDbContext();
            PasswordBox    _sender = (PasswordBox)parameter;

            List <LoginUserModel> query = (from db in dbUser.Logins
                                           where db.UserName == loginViewModel.LoginUser.UserName
                                           select db).ToList();

            if (query.Count() != 0 && (query.First().PasswordHash == hash.Hash(_sender.Password.ToString())))
            {
                MessageBox.Show("Login successfully!", "", MessageBoxButton.OK, MessageBoxImage.Information);
                this.mainModule.Visibility = System.Windows.Visibility.Visible;
                this.loginViewModel.LoginWindow.Close();
                return;
            }

            MessageBox.Show("Wrong credentials!", "Failed to login", MessageBoxButton.OK, MessageBoxImage.Asterisk);
            this.loginViewModel.LoginUser.UserName = "";
            this.loginViewModel.LoginWindow.passwordBox.Password = "";
        }
        public ActionResult Registration(User model)
        {
            try
            {
                using (var db = new LoginDbContext())
                {
                    User user = db.Users.Where(s => s.UserName == model.UserName || s.EmailId == model.EmailId).FirstOrDefault();
                    if (user == null)
                    {
                        //产生加密的盐
                        var keyNew = EncryptionHelper.GeneratePassword(10);
                        //加密密码
                        var password = EncryptionHelper.EncodePassword(model.Password, keyNew);

                        //将加密之后的密码保存到数据库
                        model.Password   = password;
                        model.CreateDate = DateTime.Now;
                        model.ModifyDate = DateTime.Now;
                        //盐
                        model.VCode = keyNew;
                        db.Users.Add(model);
                        db.SaveChanges();
                        //返回到登陆页面
                        return(RedirectToAction("Login", "Login"));
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "User Allredy Exixts!!!!!!!!!!";
                        return(View());
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = "Some exception occured" + ex;
                return(View());
            }
        }
Example #26
0
        static void Main(string[] args)
        {
            //IOC servisi yazılacak
            LoginDbContext      lgDbContext  = new LoginDbContext();
            ECommerceUnitOfWork unitOfWork   = new ECommerceUnitOfWork(lgDbContext);
            LoginService        loginService = new LoginService(unitOfWork, new EfRepository <User>(lgDbContext));


            LoginResponse loginResponse = loginService.Login(new User
            {
                Username = "******",
                Password = "******",
            });

            if (loginResponse.Code == (int)ResponseCode.SUCCESS)
            {
                Console.WriteLine(ResponseCode.SUCCESS.ToString());
            }
            else
            {
                Console.WriteLine(ResponseCode.FAILED.ToString());
            }
        }
 public CategoryController(LoginDbContext _db)
 {
     db = _db;
 }
 public RepositoryMemberStudent(LoginDbContext context) : base(context)
 {
 }
Example #29
0
        private static async Task <User> GetAdminUserAsync(IPasswordHasher <User> hasher, LoginDbContext context)
        {
            var areaId = await context.Areas.Select(x => x.Id).FirstOrDefaultAsync();

            var genderId = await context.Genders.Select(x => x.Id).FirstOrDefaultAsync();

            var admin = new User
            {
                Id                 = Guid.NewGuid().ToString("D"),
                BirthDate          = new DateTime(1998, 1, 5),
                FirstName          = "admin",
                Email              = IdentityConfig.ADMIN_EMAIL,
                NormalizedEmail    = IdentityConfig.ADMIN_EMAIL.ToUpper(),
                UserName           = IdentityConfig.ADMIN_EMAIL,
                NormalizedUserName = IdentityConfig.ADMIN_EMAIL.ToUpper(),
                PhoneNumber        = "+79996195928",
                SecurityStamp      = Guid.NewGuid().ToString("D"),
                AreaId             = areaId,
                GenderId           = genderId
            };

            admin.PasswordHash = hasher.HashPassword(admin, IdentityConfig.ADMIN_PASSWORD);

            return(admin);
        }
Example #30
0
 public LoginController(LoginDbContext LoginDbContext)
 {
     _LoginDbContext = LoginDbContext;
 }