// CreateUserWithOTP creates account with provided token and password.
// Account username and hotp generator are taken from token data.
// Deletes token after account creation.
559167
func (s *AuthServer) CreateUserWithOTP(token string, password string, otpToken string) (services.WebSession, error) {
	tokenData, err := s.GetSignupToken(token)
	if err != nil {
		log.Debugf("failed to get signup token: %v", err)
		return nil, trace.AccessDenied("expired or incorrect signup token")
	}

	err = s.UpsertTOTP(tokenData.User.Name, tokenData.OTPKey)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	err = s.CheckOTP(tokenData.User.Name, otpToken)
	if err != nil {
		log.Debugf("failed to validate a token: %v", err)
		return nil, trace.AccessDenied("failed to validate a token")
	}

	err = s.UpsertPassword(tokenData.User.Name, []byte(password))
	if err != nil {
		return nil, trace.Wrap(err)
	}

	// create services.User and services.WebSession
	webSession, err := s.createUserAndSession(tokenData)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	return webSession, nil
}
277966
func (u Users) create(session uint32) *User {
	user := &User{
		Session: session,
	}
	u[session] = user
	return user
}
1071521
func (u *UsersClient) Create(ctx context.Context, userObj *envelope.User,
	signup apitypes.Signup) (envelope.UserInf, error) {

	v := &url.Values{}
	if signup.InviteCode != "" {
		v.Set("code", signup.InviteCode)
	}
	if signup.OrgInvite && signup.OrgName != "" {
		v.Set("org", signup.OrgName)
	}
	if signup.Email != "" {
		v.Set("email", signup.Email)
	}

	e := envelope.Unsigned{}
	err := u.client.RoundTrip(ctx, "POST", "/users", v, &userObj, &e)
	if err != nil {
		return nil, err
	}

	return envelope.ConvertUser(&e)
}
1090826
func CreateRepo(c *context.APIContext, form api.CreateRepoOption) {
	owner := user.GetUserByParams(c)
	if c.Written() {
		return
	}

	repo.CreateUserRepo(c, owner, form)
}
816069
func createUser(request *restful.Request, response *restful.Response) {
	u := new(User)
	err := request.ReadEntity(u)
	log.Print("createUser", err, u)
	response.WriteEntity(u)
}
781805
func (c *client) CreateUser(ctx context.Context, name string, options *UserOptions) (User, error) {
	input := struct {
		UserOptions
		Name string `json:"user"`
	}{
		Name: name,
	}
	if options != nil {
		input.UserOptions = *options
	}
	req, err := c.conn.NewRequest("POST", path.Join("_api/user"))
	if err != nil {
		return nil, WithStack(err)
	}
	if _, err := req.SetBody(input); err != nil {
		return nil, WithStack(err)
	}
	resp, err := c.conn.Do(ctx, req)
	if err != nil {
		return nil, WithStack(err)
	}
	if err := resp.CheckStatus(201); err != nil {
		return nil, WithStack(err)
	}
	var data userData
	if err := resp.ParseBody("", &data); err != nil {
		return nil, WithStack(err)
	}
	u, err := newUser(data, c.conn)
	if err != nil {
		return nil, WithStack(err)
	}
	return u, nil
}
379353
func WithUser(username string, org string) UsersOption {
	return func(mgr *UsersOptions) error {
		if mgr.users != nil {
			return errors.New("already initialized")
		}
		mgr.users = make(map[string]msp.SigningIdentity)
		mgr.users[username] = mspmocks.NewMockSigningIdentity(username, org)
		return nil
	}
}
749878
func (store *Store) createUserWithBits(login, password string, bits int) (u *User, e error) {
	if store.UserExists(login) {
		return nil, fmt.Errorf("user already exists")
	}
	user := &User{}
	dir := store.userPath(login)
	log.Printf("creating directory %s", dir)
	e = os.MkdirAll(dir, 0755)
	if e != nil {
		return nil, e
	}
	log.Printf("generating key with %d bits", DefaultBits)
	started := time.Now()
	key, e := rsa.GenerateKey(rand.Reader, bits)
	if e != nil {
		return nil, e
	}
	log.Printf("generated key in %.3f", time.Since(started).Seconds())
	b, e := json.Marshal(key.PublicKey)
	if e != nil {
		return nil, e
	}
	e = ioutil.WriteFile(dir+"/id_rsa.pub", b, 0600)
	if e != nil {
		return nil, e
	}
	crypter := newCrypter(hashPassword(password))
	b, e = json.Marshal(key)
	if e != nil {
		os.Remove(dir + "/id_rsa.pub")
		return nil, e
	}
	ct, e := crypter.Encrypt(b)
	if e != nil {
		os.Remove(dir + "/id_rsa.pub")
		return nil, e
	}
	dst := []byte(b64.EncodeToString(ct))
	e = ioutil.WriteFile(dir+"/id_rsa", dst, 0600)
	if e != nil {
		os.Remove(dir + "/id_rsa.pub")
		return nil, e
	}
	return user, nil
}
944180
func (s stage) createUsers(config types.Config) error {
	if len(config.Passwd.Users) == 0 {
		return nil
	}
	s.Logger.PushPrefix("createUsers")
	defer s.Logger.PopPrefix()

	for _, u := range config.Passwd.Users {
		if err := s.EnsureUser(u); err != nil {
			return fmt.Errorf("failed to create user %q: %v",
				u.Name, err)
		}

		if err := s.SetPasswordHash(u); err != nil {
			return fmt.Errorf("failed to set password for %q: %v",
				u.Name, err)
		}

		if err := s.AuthorizeSSHKeys(u); err != nil {
			return fmt.Errorf("failed to add keys to user %q: %v",
				u.Name, err)
		}
	}

	return nil
}
1179445
func (s *UserService) Create(user *User) (*User, *Response, error) {
	apiEndpoint := "/rest/api/2/user"
	req, err := s.client.NewRequest("POST", apiEndpoint, user)
	if err != nil {
		return nil, nil, err
	}

	resp, err := s.client.Do(req, nil)
	if err != nil {
		return nil, resp, err
	}

	responseUser := new(User)
	defer resp.Body.Close()
	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		e := fmt.Errorf("Could not read the returned data")
		return nil, resp, NewJiraError(resp, e)
	}
	err = json.Unmarshal(data, responseUser)
	if err != nil {
		e := fmt.Errorf("Could not unmarshall the data into struct")
		return nil, resp, NewJiraError(resp, e)
	}
	return responseUser, resp, nil
}
607987
func (s *Service) CreateUser(ctx context.Context, u *influxdb.User) error {
	return s.kv.Update(ctx, func(tx Tx) error {
		return s.createUser(ctx, tx, u)
	})
}
198311
func (s *Service) OAuthTokenCreate(ctx context.Context, o OAuthTokenCreateOpts) (*OAuthToken, error) {
	var oauthToken OAuthToken
	return &oauthToken, s.Post(ctx, &oauthToken, fmt.Sprintf("/oauth/tokens"), o)
}
143458
func (c *Client) CreateUser(user User) (*ParseUser, error) {
	payload, err := json.Marshal(user)
	c.trace("CreateUser >", "/1/users", string(payload))
	resp, err := c.doWithBody("POST", "/1/users", bytes.NewReader(payload))
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	var u *ParseUser
	err = json.Unmarshal(body, &u)
	c.trace("CreateUser <", "/1/users", string(body))
	return u, err
}
92070
func (c *FakeOAuthAuthorizeTokens) Create(oAuthAuthorizeToken *oauth.OAuthAuthorizeToken) (result *oauth.OAuthAuthorizeToken, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewRootCreateAction(oauthauthorizetokensResource, oAuthAuthorizeToken), &oauth.OAuthAuthorizeToken{})
	if obj == nil {
		return nil, err
	}
	return obj.(*oauth.OAuthAuthorizeToken), err
}
887170
func CreateWallet(mctx libkb.MetaContext) (created bool, err error) {
	defer mctx.TraceTimed("Stellar.CreateWallet", func() error { return err })()
	loggedInUsername := mctx.ActiveDevice().Username(mctx)
	if !loggedInUsername.IsValid() {
		return false, fmt.Errorf("could not get logged-in username")
	}
	perUserKeyUpgradeSoft(mctx, "create-wallet")
	clearBundle, err := bundle.NewInitial(fmt.Sprintf("%v's account", loggedInUsername))
	if err != nil {
		return false, err
	}
	meUV, err := mctx.G().GetMeUV(mctx.Ctx())
	if err != nil {
		return false, err
	}
	err = remote.PostWithChainlink(mctx, *clearBundle)
	switch e := err.(type) {
	case nil:
		// ok
	case libkb.AppStatusError:
		switch keybase1.StatusCode(e.Code) {
		case keybase1.StatusCode_SCStellarWrongRevision:
			// Assume this happened because a bundle already existed.
			// And suppress the error.
			mctx.Debug("suppressing error: %v", err)
			return false, nil
		}
		return false, err
	default:
		return false, err
	}
	getGlobal(mctx.G()).InformHasWallet(mctx.Ctx(), meUV)
	go getGlobal(mctx.G()).KickAutoClaimRunner(mctx.BackgroundWithLogTags(), gregor1.MsgID{})
	return true, nil
}
1001096
func (a *Account) WithAuth(strategy auth.Strategy) *Account {
	a.auth = strategy
	return a
}
27608
func (i *Influxdb) CreateUser(ctx context.Context, statements dbplugin.Statements, usernameConfig dbplugin.UsernameConfig, expiration time.Time) (username string, password string, err error) {
	// Grab the lock
	i.Lock()
	defer i.Unlock()

	statements = dbutil.StatementCompatibilityHelper(statements)

	// Get the connection
	cli, err := i.getConnection(ctx)
	if err != nil {
		return "", "", err
	}

	creationIFQL := statements.Creation
	if len(creationIFQL) == 0 {
		creationIFQL = []string{defaultUserCreationIFQL}
	}

	rollbackIFQL := statements.Rollback
	if len(rollbackIFQL) == 0 {
		rollbackIFQL = []string{defaultUserDeletionIFQL}
	}

	username, err = i.GenerateUsername(usernameConfig)
	username = strings.Replace(username, "-", "_", -1)
	if err != nil {
		return "", "", err
	}
	username = strings.ToLower(username)
	password, err = i.GeneratePassword()
	if err != nil {
		return "", "", err
	}

	// Execute each query
	for _, stmt := range creationIFQL {
		for _, query := range strutil.ParseArbitraryStringSlice(stmt, ";") {
			query = strings.TrimSpace(query)
			if len(query) == 0 {
				continue
			}

			q := influx.NewQuery(dbutil.QueryHelper(query, map[string]string{
				"username": username,
				"password": password,
			}), "", "")
			response, err := cli.Query(q)
			if err != nil && response.Error() != nil {
				for _, stmt := range rollbackIFQL {
					for _, query := range strutil.ParseArbitraryStringSlice(stmt, ";") {
						query = strings.TrimSpace(query)

						if len(query) == 0 {
							continue
						}
						q := influx.NewQuery(dbutil.QueryHelper(query, map[string]string{
							"username": username,
						}), "", "")

						response, err := cli.Query(q)
						if err != nil && response.Error() != nil {
							return "", "", err
						}
					}
				}
				return "", "", err
			}
		}
	}
	return username, password, nil
}