public int RegisterUser(AccountUpsertRequest userModel) { int userId = 0; string salt; string passwordHash; string password = userModel.Password; salt = _cryptographyService.GenerateRandomString(RAND_LENGTH); passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT); _dataProvider.ExecuteNonQuery("dbo.Person_UpsertAccount", inputParamMapper: delegate (SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Id", userModel.Id); paramCollection.AddWithValue("@FirstName", userModel.FirstName); paramCollection.AddWithValue("@LastName", userModel.LastName); paramCollection.AddWithValue("@Email", userModel.Email); paramCollection.AddWithValue("@Salt", salt); paramCollection.AddWithValue("@PasswordHash", passwordHash); paramCollection.AddWithValue("@RoleId", userModel.RoleId); //SqlParameter idParameter = new SqlParameter("@Id", SqlDbType.Int); //idParameter.Direction = ParameterDirection.Output; //paramCollection.Add(idParameter); } ); SendEmailConfirmationEmail(userModel.Email); return userId; //DB provider call to create user and get us a user id //be sure to store both salt and passwordHash //DO NOT STORE the original password value that the user passed us }
//======================================Register==================================== public int CreateUser(RegisterAddRequest registerAddRequest) { int id = 0; string password = registerAddRequest.Password; string salt = _cryptographyService.GenerateRandomString(RAND_LENGTH); string passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT); this._dataProvider.ExecuteNonQuery( // "Emma_User_Insert", "HRB_user_insert", inputParamMapper : delegate(SqlParameterCollection paramList) { SqlParameter param = new SqlParameter(); param.ParameterName = "@Id"; param.SqlDbType = System.Data.SqlDbType.Int; param.Direction = System.Data.ParameterDirection.Output; paramList.Add(param); paramList.AddWithValue("Email", registerAddRequest.Email); paramList.AddWithValue("FirstName", registerAddRequest.FirstName); paramList.AddWithValue("MiddleInitial", registerAddRequest.MiddleInitial); paramList.AddWithValue("LastName", registerAddRequest.LastName); paramList.AddWithValue("Password", passwordHash); paramList.AddWithValue("ConfirmPassword", passwordHash); paramList.AddWithValue("Salt", salt); }, returnParameters : delegate(SqlParameterCollection paramList) { id = (int)paramList["@Id"].Value; } ); return(id); }
public int Create(UserAddRequest userModel, string role) { string salt; string passwordHash; string password = userModel.Password; salt = _cryptographyService.GenerateRandomString(RAND_LENGTH); passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT); //DB provider call to create user and get us a user id //be sure to store both salt and passwordHash //DO NOT STORE the original password value that the user passed us int userId = Add(userModel, salt, passwordHash, role); return(userId); }
//Function - Takes a RegisterAddModel and creates a base account in the database // - returns the Id of the new account public int CreateBaseAccount(RegisterAddModel model) { //Generates a random string for the password model.Password = _cryptoService.GenerateRandomString(12); //Sets the email confirmed to true because their email is confirmed through the third party model.EmailConfirmed = true; model.ModifiedBy = model.Email; //Calls the InsertNewUser from the user service to create the base account int accountId = _userService.InsertNewUser(model); return(accountId); }
// [CREATE] public int Create(RegistrationAddRequest userModel) { int result = 0; string salt; string passwordHash; string password = userModel.Password; bool isConfirmed = false; bool isActive = false; salt = _cryptographyService.GenerateRandomString(RAND_LENGTH); passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT); //DB provider call to create user and get us a user id this.DataProvider.ExecuteNonQuery( "Users_Insert", inputParamMapper : delegate(SqlParameterCollection paramCol) { SqlParameter parm = new SqlParameter(); parm.ParameterName = "@Id"; parm.SqlDbType = SqlDbType.Int; parm.Direction = ParameterDirection.Output; paramCol.Add(parm); paramCol.AddWithValue("@FirstName", userModel.FirstName); paramCol.AddWithValue("@LastName", userModel.LastName); paramCol.AddWithValue("@Email", userModel.Email); paramCol.AddWithValue("@Pass", passwordHash); paramCol.AddWithValue("@Salt", salt); paramCol.AddWithValue("@isConfirmed", isConfirmed); paramCol.AddWithValue("@isActive", isActive); }, returnParameters : delegate(SqlParameterCollection paramCol) { result = (int)paramCol["@Id"].Value; } ); //be sure to store both salt and passwordHash //DO NOT STORE the original password value that the user passed us return(result); }
//Register User //Adds User data into UserBase DB and sets Anon Role to UserRoles DB //Adds name and phone info to respective db tables public int Create(RegisterUserRequest model) { int Id = 0; string salt = _cryptographyService.GenerateRandomString(RAND_LENGTH); string passwordHash = _cryptographyService.Hash(model.Password, salt, HASH_ITERATION_COUNT); DataProvider.ExecuteNonQuery(storedProc : "dbo.UserBase_Insert", inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Email", model.Email); paramCollection.AddWithValue("@PasswordHash", passwordHash); paramCollection.AddWithValue("@Salt", salt); paramCollection.AddWithValue("@FirstName", model.FirstName); paramCollection.AddWithValue("@LastName", model.LastName); if (model.CountryCode == null) { model.CountryCode = ""; } paramCollection.AddWithValue("@CountryCode", model.CountryCode); paramCollection.AddWithValue("@PhoneNumber", model.PhoneNumber); if (model.Extension == null) { model.Extension = ""; } paramCollection.AddWithValue("@Extension", model.Extension); SqlParameter idParameter = new SqlParameter("@Id", System.Data.SqlDbType.Int); idParameter.Direction = System.Data.ParameterDirection.Output; paramCollection.Add(idParameter); }, returnParameters : delegate(SqlParameterCollection param) { Int32.TryParse(param["@Id"].Value.ToString(), out Id); }); return(Id); }
public int Create(object userModel) { int userId = 0; string salt; string passwordHash; string password = "******"; salt = _cryptographyService.GenerateRandomString(RAND_LENGTH); passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT); //DB provider call to create user and get us a user id //be sure to store both salt and passwordHash //DO NOT STORE the original password value that the user passed us return(userId); }
// CRUD operations public int Create(UserBaseCreateRequest request) { int id = 0; string salt; string passwordHash; string password = request.Password; // Get from user model when you have a concrete class salt = _cryptographyService.GenerateRandomString(RAND_LENGTH); passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT); try { //DB provider call to create user and get us a user id _dataProvider.ExecuteNonQuery( "user_create", inputParamMapper : delegate(SqlParameterCollection parameters) { // if the thing on the left is 'null' use the thing on the right parameters.AddWithValue("@FullName", request.FullName ?? (object)DBNull.Value); parameters.AddWithValue("@Username", request.UserName); parameters.AddWithValue("@EmailAddress", request.EmailAddress); parameters.AddWithValue("@Password", passwordHash); parameters.AddWithValue("@Salt", salt); SqlParameter idParam = parameters.Add("@Id", SqlDbType.Int); idParam.Direction = ParameterDirection.Output; }, returnParameters : delegate(SqlParameterCollection parameters) { id = (int)parameters["@Id"].Value; }); //be sure to store both salt and passwordHash //DO NOT STORE the original password value that the user passed us } catch (SqlException exception) when(exception.Number == 2627) { throw new DuplicateNameException("A user with that user name or email address already exists."); } return(id); }
public string Register(RegisterRequestModel info) { string guid = ""; string salt = _cryptographyService.GenerateRandomString(15); string passwordHash = _cryptographyService.Hash(info.Password, salt); SqlParameter outParam = new SqlParameter("@GUID", System.Data.SqlDbType.NVarChar, 128); outParam.Direction = System.Data.ParameterDirection.Output; Adapter.ExecuteNonQuery("dbo.User_Insert", new[] { new SqlParameter("@email", info.Email), new SqlParameter("@userName", info.UserName), new SqlParameter("@passwordHash", passwordHash), new SqlParameter("@salt", salt), outParam }, (parameters) => { guid = parameters.GetParamValue <string>("@guid"); }); return(guid); }
// [CREATE] public int Create(ThirdPartyUserLogin userModel) { int result = 0; string salt; string passwordHash; string password = userModel.Password; bool isConfirmed = true; bool isActive = true; salt = _cryptographyService.GenerateRandomString(RAND_LENGTH); passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT); //DB provider call to create user and get us a user id this.DataProvider.ExecuteNonQuery( "Users_Insert", inputParamMapper : delegate(SqlParameterCollection paramCol) { SqlParameter parm = new SqlParameter(); parm.ParameterName = "@Id"; parm.SqlDbType = SqlDbType.Int; parm.Direction = ParameterDirection.Output; paramCol.Add(parm); paramCol.AddWithValue("@Email", userModel.Email); paramCol.AddWithValue("@Pass", passwordHash); paramCol.AddWithValue("@Salt", salt); paramCol.AddWithValue("@isConfirmed", isConfirmed); paramCol.AddWithValue("@isActive", isActive); paramCol.AddWithValue("@FirstName", userModel.FirstName); paramCol.AddWithValue("@MiddleInitial", userModel.MiddleInitial); paramCol.AddWithValue("@LastName", userModel.LastName); paramCol.AddWithValue("@Location", userModel.Location); paramCol.AddWithValue("@ThirdpartyTypeId", userModel.ThirdPartTypeId); paramCol.AddWithValue("@AccountId", userModel.AccountId); }, returnParameters : delegate(SqlParameterCollection paramCol) { result = (int)paramCol["@Id"].Value; } ); return(result); }
// [CREATE] public int Create(ThirdPartyUserLogin userModel) { TransferUtility utility = new TransferUtility(awsS3Client); TransferUtilityUploadRequest request = new TransferUtilityUploadRequest(); var newGuid = Guid.NewGuid().ToString(""); var newFileName = "ThirdParty_ProfilePic_" + newGuid; string ProfileUrl = userModel.Location; var client = new WebClient(); var content = client.DownloadData(ProfileUrl); var stream = new MemoryStream(content); request.BucketName = bucketname; request.Key = newFileName; request.InputStream = stream; utility.Upload(request); userModel.Password = userModel.AccountId; int result = 0; string salt; string passwordHash; string password = userModel.Password; bool isConfirmed = true; bool isActive = true; salt = _cryptographyService.GenerateRandomString(RAND_LENGTH); passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT); //DB provider call to create user and get us a user id this.DataProvider.ExecuteNonQuery( "ThirdPartyUsers_Register", inputParamMapper : delegate(SqlParameterCollection paramCol) { List <SqlParameter> parm = new List <SqlParameter>() { new SqlParameter("@UserId", SqlDbType.Int), new SqlParameter("@PersonId", SqlDbType.Int), new SqlParameter("@FileStorageId", SqlDbType.Int) }; foreach (var item in parm) { item.Direction = ParameterDirection.Output; } paramCol.AddRange(parm.ToArray()); paramCol.AddWithValue("@Email", userModel.Email); paramCol.AddWithValue("@Pass", passwordHash); paramCol.AddWithValue("@Salt", salt); paramCol.AddWithValue("@isConfirmed", isConfirmed); paramCol.AddWithValue("@isActive", isActive); paramCol.AddWithValue("@FirstName", userModel.FirstName); paramCol.AddWithValue("@MiddleInitial", userModel.MiddleInitial); paramCol.AddWithValue("@LastName", userModel.LastName); paramCol.AddWithValue("@FileTypeId", 1); paramCol.AddWithValue("@UserFileName", "ThirdParty_ProfileImg"); paramCol.AddWithValue("@SystemFileName", "ThirdParty_ProfileImg"); paramCol.AddWithValue("@Location", "https://sabio-training.s3.us-west-2.amazonaws.com/C53/" + newFileName); paramCol.AddWithValue("@CreatedBy", userModel.Email); paramCol.AddWithValue("@ThirdPartyTypeId", userModel.ThirdPartyTypeId); paramCol.AddWithValue("@AccountId", userModel.AccountId); }, returnParameters : delegate(SqlParameterCollection paramCol) { result = (int)paramCol["@UserId"].Value; } ); return(result); }
public int Create(AccountUpsertRequest userModel) { int userId = 0; string salt; string passwordHash; string password = userModel.Password; salt = _cryptographyService.GenerateRandomString(RAND_LENGTH); passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT); _dataProvider.ExecuteNonQuery("dbo.Person_UpsertAccount", inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Id", userModel.Id); paramCollection.AddWithValue("@FirstName", userModel.FirstName); paramCollection.AddWithValue("@LastName", userModel.LastName); paramCollection.AddWithValue("@Email", userModel.Email); paramCollection.AddWithValue("@Salt", salt); paramCollection.AddWithValue("@PasswordHash", passwordHash); paramCollection.AddWithValue("@RoleId", userModel.RoleId); //SqlParameter idParameter = new SqlParameter("@Id", SqlDbType.Int); //idParameter.Direction = ParameterDirection.Output; //paramCollection.Add(idParameter); } //, //returnParameters: delegate (SqlParameterCollection param) //{ // Int32.TryParse(param["@Id"].Value.ToString(), out userId); //} ); //1)creating token SecurityTokenService sts = new SecurityTokenService(_dataProvider); SecurityTokenAddRequest star = new SecurityTokenAddRequest() { TokenTypeId = 1, UserEmail = userModel.Email }; System.Guid tokenGuid = sts.Insert(star); //2)emailing confirmation var source = SiteConfig.BaseUrl; var message = "<body style='margin: 0; padding: 0; background:#ccc;'><table cellpadding=0 cellspacing=0 style='width: 100%;'><tr><td style='padding: 12px 2%;'><table cellpadding=0 cellspacing=0 style='margin:auto; background: #fff; width: 96%;'><tr><td style='padding: 12px 2%;'><div><h1 style='color:white;background-color:#1E90FF;'>Youth Mentoring Connection</h1></div > <div><h2 style='margin-top: 0;'>Congratulations</h2><p>You've successfully registered. Please confirm your email with Youth Mentoring Connection.To confirm your email click the link below:<br/></br> <span style='text-align:center; margin:0;'><a href=" + source + "/confirmationPages?guid=" + tokenGuid + ">Click Here To Confirm Email</a></p><p>...</p></div><div><h4 style='margin-top: 0;'>Sawubona!</h4><p></p></div><div style='border-top: solid 1px #ccc;'><p></p></div></td ></tr ></table ></td ></tr ></table ></body >"; ConfirmationEmailService ces = new ConfirmationEmailService(); ConfirmationEmailRequest cer = new ConfirmationEmailRequest() { From = "*****@*****.**", To = userModel.Email, Subject = "YMC Confirmation", Body = message }; Task <bool> email = ces.Execute(cer); return(userId); //DB provider call to create user and get us a user id //be sure to store both salt and passwordHash //DO NOT STORE the original password value that the user passed us }
private void PasswordHasher(string password, out string salt, out string passwordHash) { salt = _cryptographyService.GenerateRandomString(15); passwordHash = _cryptographyService.Hash(password, salt, 1); }