当前位置: 首页>>代码示例>>C#>>正文


C# User.SetPassword方法代码示例

本文整理汇总了C#中User.SetPassword方法的典型用法代码示例。如果您正苦于以下问题:C# User.SetPassword方法的具体用法?C# User.SetPassword怎么用?C# User.SetPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在User的用法示例。


在下文中一共展示了User.SetPassword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddUser

        /// <summary>
        /// Adds a user to the system, and sets the <see cref="User.IsActivated"/> to true.
        /// </summary>
        /// <param name="email">The email or username.</param>
        /// <param name="password">The password.</param>
        /// <param name="isAdmin">if set to <c>true</c> the user is added as an admin.</param>
        /// <param name="isEditor">if set to <c>true</c> the user is added as an editor.</param>
        /// <returns>
        /// true if the user was added; false if the user already exists.
        /// </returns>
        /// <exception cref="SecurityException">An NHibernate (database) error occurred while adding the new user.</exception>
        public override bool AddUser(string email, string username, string password, bool isAdmin, bool isEditor)
        {
            try
            {
                User user = Users.FirstOrDefault(u => u.Email == email || u.Username == username);
                if (user == null)
                {
                    user = new User();
                    user.Email = email;
                    user.Username = username;
                    user.SetPassword(password);
                    user.IsAdmin = isAdmin;
                    user.IsEditor = isEditor;
                    user.IsActivated = true;
                    NHibernateRepository.Current.SaveOrUpdate<User>(user);

                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (HibernateException ex)
            {
                throw new SecurityException(ex, "An error occurred while adding the new user {0}", email);
            }
        }
开发者ID:Yodadude,项目名称:Roadkill,代码行数:39,代码来源:SqlUserManager.cs

示例2: VaildatePassword_Success_When_PasswordCorrect

 public void VaildatePassword_Success_When_PasswordCorrect()
 {
     var user = new User();
     const string password = "test";
     user.SetPassword(password);
     Assert.True(user.VaildatePassword(password));
 }
开发者ID:ZA-PT,项目名称:Obsidian,代码行数:7,代码来源:UserTest.cs

示例3: Execute

        public override void Execute()
        {
            var user = new User(_login, _email);
            user.SetPassword(_password);

            EntityStore.Save(user);
        }
开发者ID:JefClaes,项目名称:topdevlinks,代码行数:7,代码来源:AddUserCommand.cs

示例4: SetUp

        public void SetUp()
        {
            MongoContext.GetCollection<User>().Drop();

            var user = new User("JefClaes", "[email protected]");
            user.SetPassword("abc.123");

            EntityStore.Save(user);

            _userId = user.Id;
        }
开发者ID:JefClaes,项目名称:topdevlinks,代码行数:11,代码来源:DeactivateUserCommandTest.cs

示例5: Reg

		/// <summary>
		/// 注册用户
		/// 注册失败时会抛出例外
		/// </summary>
		public virtual void Reg(
			string username, string password, Action<User> update = null) {
			var databaseManager = Application.Ioc.Resolve<DatabaseManager>();
			using (var context = databaseManager.GetContext()) {
				var user = new User();
				user.Type = UserTypes.User;
				user.Username = username;
				user.SetPassword(password);
				user.CreateTime = DateTime.UtcNow;
				context.Save(ref user, update);
				context.SaveChanges();
			}
		}
开发者ID:daywrite,项目名称:ZKWeb.Plugins,代码行数:17,代码来源:UserManager.cs

示例6: Main

        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("You need to provide 3 arguments: the login, the emailaddress and the password");
                return;
            }

            var user = new User(args[0], args[1]);
            user.SetPassword(args[2]);

            var entityStore = new EntityStore(new MongoContext());

            entityStore.Save(user);
        }
开发者ID:JefClaes,项目名称:topdevlinks,代码行数:15,代码来源:Program.cs

示例7: New

        public ActionResult New(UsersNew form)
        {
            var user = new User();
            SyncRoles(form.Roles, user.Roles);

            if (Database.Session.Query<User>().Any(u => u.Username == form.Username))
                ModelState.AddModelError("Username", "Username must be unique");

            if (!ModelState.IsValid)
                return View(form);

            user.Email = form.Email;
            user.Username = form.Username;
            user.SetPassword(form.Password);

            Database.Session.Save(user);

            return RedirectToAction("index");
        }
开发者ID:killerrin,项目名称:Simple-Blog,代码行数:19,代码来源:UsersController.cs

示例8: OnLoad

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        if (Request.Form.Count > 0) {
            // Registration form has been submitted
            Email = Request.Form["email"];
            Password = Request.Form["password"];
            Confirm = Request.Form["confirm"];
            FirstName = Request.Form["first-name"];
            LastName = Request.Form["last-name"];

            // Error check
            AssertIsEqual(Password, Confirm, "Password does not match");
            AssertExists(LastName, "Last Name is required");
            AssertExists(FirstName, "First Name is required");
            AssertExists(Password, "Password is required");
            AssertExists(Email, "Email is required");

            if (!HasError) {
                // Add to database
                User user = new User();
                user.Email = Email;
                user.SetPassword(Password);
                user.FirstName = FirstName;
                user.LastName = LastName;
                user.Birthday = GetBirthday();

                UserStore.Insert(ref user);

                // Login and redirect
                LoginStore.Login(user);
                Response.Redirect("/download.aspx");
            }
        } else {
            Email = "[email protected]";
            FirstName = "Ryan";
            LastName = "Shaul";
            Password = "asdf";
            Confirm = "asdf";
        }
    }
开发者ID:RyanShaul,项目名称:dig,代码行数:42,代码来源:register.aspx.cs

示例9: Run

        public override void Run()
        {
            Console.Write("Creating admin user group and user... ");

            using (Context context = ContextManager.Instance.CreateContext(ConnectionMode.AutoOpen, TransactionMode.AutoCommit))
            {
                var f = new EntityFactory(context);
                var c = f.LoadEntity<Cluster>(clusterName);

                var u = new User(c)
                {
                    Name = adminUsername,
                    Email = adminEmail,
                    DeploymentState = Registry.DeploymentState.Deployed,
                };
                u.SetPassword(adminPassword);
                u.Save();

                // TODO: create admin group membership
            }

            Console.WriteLine("done.");
        }
开发者ID:horvatferi,项目名称:graywulf,代码行数:23,代码来源:CreateAdmin.cs

示例10: New

        public ActionResult New(UsersNew form)
        {
            if (Database.Session.Query<User>().Any(u => u.Username == form.Username))
            {
                ModelState.AddModelError("Username", "Username must be unique");
            }

            if (!ModelState.IsValid)
            {
                return View(form);
            }

            var user = new User
            {
                Email = form.Email,
                Username = form.Username
            };

            user.SetPassword(form.Password);

            Database.Session.Save(user);

            return RedirectToAction("Index");
        }
开发者ID:jimxshaw,项目名称:samples-csharp,代码行数:24,代码来源:UsersController.cs

示例11: Signup

        /// <summary>
        /// Creates a user in the system without setting the <see cref="User.IsActivated"/>, in other words for a user confirmation email.
        /// </summary>
        /// <param name="user">The user details to signup.</param>
        /// <param name="completed">Called once the signup (e.g. email is sent) is complete. Pass Null for no action.</param>
        /// <returns>
        /// The activation key for the signup.
        /// </returns>
        public override string Signup(UserSummary summary, Action completed)
        {
            if (summary == null)
                throw new SecurityException("The summary provided to Signup is null.", null);

            try
            {
                // Create the new user
                summary.ActivationKey = Guid.NewGuid().ToString();
                User user = new User();
                user.Username = summary.NewUsername;
                user.ActivationKey = summary.ActivationKey;
                user.Email = summary.NewEmail;
                user.Firstname = summary.Firstname;
                user.Lastname = summary.Lastname;
                user.SetPassword(summary.Password);
                user.IsEditor = true;
                user.IsAdmin = false;
                user.IsActivated = false;
                NHibernateRepository.Current.SaveOrUpdate<User>(user);

                if (completed != null)
                    completed();

                return user.ActivationKey;
            }
            catch (HibernateException ex)
            {
                throw new SecurityException(ex, "An error occurred with the signup of {0}", summary.NewEmail);
            }
        }
开发者ID:Yodadude,项目名称:Roadkill,代码行数:39,代码来源:SqlUserManager.cs

示例12: Register

        public ActionResult Register(User user, string password, string confirmPassword)
        {
            ViewData["Title"] = "Register";

            // Non-POST requests should just display the Register form
            if (Request != null && Request.HttpMethod != "POST")
                return View();

            Validator validator = new Validator();

            validator.Required(user.UserName, "You must enter a UserName")
                .Required(user.Email, "You must enter an email Address")
                .Required(password, "You must enter a valid Password")
                .ShouldBeSame(password, confirmPassword, "Password and Confirmation Password need to match");

            if (validator.Errors.Count == 0)
            {
                user.SetPassword(password);
                _UserRepository.Save(user);
                FormsAuth.SignIn(user.UserName, true);
                return RedirectToAction("Index", "Home");
               }

            // If we got this far, something failed, redisplay form
            ViewData["errors"] = validator.Errors;
            ViewData["username"] = user.UserName;
            ViewData["email"] = user.Email;
            return View();
        }
开发者ID:ignu,项目名称:tribality,代码行数:29,代码来源:AccountController.cs

示例13: Register

        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    var newUser = new User();
                    newUser.SetPassword(model.Password);
                    newUser.UserName = model.UserName;
                    newUser.Email = model.Email;
                    newUser.Enabled = true;

                    RavenSession.Store(newUser);

                    RavenSession.SaveChanges();

                    //WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    FormsAuthentication.SetAuthCookie(newUser.UserName, true);

                    //WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
开发者ID:larserikfinholt,项目名称:Logit,代码行数:32,代码来源:AccountController.cs

示例14: VaildatePassword_Fail_When_PasswordWrong

 public void VaildatePassword_Fail_When_PasswordWrong()
 {
     var user = new User();
     user.SetPassword("test");
     Assert.False(user.VaildatePassword("wrong"));
 }
开发者ID:ZA-PT,项目名称:Obsidian,代码行数:6,代码来源:UserTest.cs

示例15: UpdateDatabaseAfterUpdateSchema

        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            NestedUnitOfWork UOW = this.Session.BeginNestedUnitOfWork();
            UOW.BeginTransaction();
            //khoi tao quan tai khoan quan tri he thong (mau)
            User systemAmdmin = UOW.FindObject<User>(new BinaryOperator("UserName", "SystemAdmin"));
            if (systemAmdmin == null)
            {
                systemAmdmin = new User(UOW);
                systemAmdmin.UserName = "SystemAdmin";
                systemAmdmin.SetPassword("SystemAdmin");
            }
            //khoi tao quan tai khoan sinh vien (mau)
            Student student = UOW.FindObject<Student>(new BinaryOperator("UserName", "SampleStudent"));
            if (student == null)
            {
                student = new Student(UOW);
                student.UserName = "SampleStudent";
                student.SetPassword("SampleStudent");
            }
            User guest = UOW.FindObject<User>(new BinaryOperator("UserName", "guest"));
            if (guest == null)
            {
                guest = new User(UOW);
                guest.UserName = "guest";
                guest.SetPassword("guest");
            }
            //khoi tao quan tai khoan quan quan ly dao tao
            User dataAdmin = UOW.FindObject<User>(new BinaryOperator("UserName", "DataAdmin"));
            if (dataAdmin == null)
            {
                dataAdmin = new User(UOW);
                dataAdmin.UserName = "DataAdmin";
                dataAdmin.SetPassword("DataAdmin");
            }

            // If a role with the Administrators name does not exist in the database, create this role
            Role adminRole = UOW.FindObject<Role>(new BinaryOperator("Name", "Administrators"));
            if (adminRole == null)
            {
                adminRole = new Role(UOW);
                adminRole.Name = "Administrators";
            }
            // If a role with the Users name does not exist in the database, create this role
            Role userRole = UOW.FindObject<Role>(new BinaryOperator("Name", "Users"));
            if (userRole == null)
            {
                userRole = new Role(UOW);
                userRole.Name = "Users";
            }

            // If a role with the Users name does not exist in the database, create this role
            Role dataRole = UOW.FindObject<Role>(new BinaryOperator("Name", "DataAdmins"));
            if (dataRole == null)
            {
                dataRole = new Role(UOW);
                dataRole.Name = "DataAdmins";
            }

            Role studentRole = UOW.FindObject<Role>(new BinaryOperator("Name", "Students"));
            if (studentRole == null)
            {
                studentRole = new Role(UOW);
                studentRole.Name = "Students";
            }

             //Delete all permissions assigned to the Administrators and Users roles

            while (adminRole.PersistentPermissions.Count > 0)
            {
                UOW.Delete(adminRole.PersistentPermissions[0]);
            }
            while (userRole.PersistentPermissions.Count > 0)
            {
                UOW.Delete(userRole.PersistentPermissions[0]);
            }
            while (dataRole.PersistentPermissions.Count > 0)
            {
                UOW.Delete(dataRole.PersistentPermissions[0]);
            }
            while (studentRole.PersistentPermissions.Count > 0)
            {
                UOW.Delete(studentRole.PersistentPermissions[0]);
            }
            UOW.PurgeDeletedObjects();

            // Allow full access to all objects to the Administrators role
            adminRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.AllAccess));
            // Allow editing the Application Model to the Administrators role
            adminRole.AddPermission(new EditModelPermission(ModelAccessModifier.Allow));
            // Save the Administrators role to the database
            adminRole.Save();

            // Allow full access to all objects to the DataAdmins role
            dataRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.AllAccess));
            // Allow editing the Application Model to the Administrators role
            dataRole.AddPermission(new EditModelPermission(ModelAccessModifier.Allow));
            // Save the Administrators role to the database
            dataRole.Save();
//.........这里部分代码省略.........
开发者ID:dedangkyphanmem,项目名称:vidodkmh,代码行数:101,代码来源:Updater.cs


注:本文中的User.SetPassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。