示例#1
0
文件: account.go 项目: markpasc/cares
func (account *Account) SetPassword(pass string) error {
	hash, err := bcrypt.Hash(pass)
	if err == nil {
		account.PasswordHash = hash
	}
	return err
}
示例#2
0
func InitTests() {
	server = httptest.NewServer(createRouter())
	connectToRedis = func() *redis.Client {
		// CONFIGURE THIS!
		password := ""
		client := redis.NewTCPClient("localhost:6379", password, 1)
		return client
	}
	client := connectToRedis()
	defer client.Close()
	client.FlushDb()
	// Bootstrap the system, with an admin
	hash, _ := bcrypt.Hash("asdf")
	client.HMSet("user:admin", "isadmin", "1", "password", hash)
}
示例#3
0
文件: service.go 项目: inve1/idyns
func UserPut(w http.ResponseWriter, r *http.Request) {
	name := mux.Vars(r)["username"]
	password := r.FormValue("password")
	auth, _ := NewBasicFromRequest(r)
	if checkPermUsr(auth, name) {
		client := connectToRedis()
		defer client.Close()
		if client.Exists("user:"******"user:"******"password", hash)
			fmt.Fprintf(w, "")
		} else {
			http.Error(w, "", 404)
		}
	} else {
		http.Error(w, "", 403)
	}

}
示例#4
0
文件: auth.go 项目: natmeox/mess
func (w *DatabaseWorld) CreateAccount(name, password string) (acc *Account) {
	passwordHash, err := bcrypt.Hash(password)
	if err != nil {
		log.Println("Couldn't hash password to create an account:", err.Error())
		return nil
	}

	// TODO: Config setting for where to start new players?
	origin := World.ThingForId(1)
	char := World.CreateThing(name, PlayerThing, nil, origin)
	if char == nil {
		log.Println("Couldn't create character to create an account")
		return nil
	}

	tx, err := w.db.Begin()
	if err != nil {
		log.Println("Couldn't open transaction to create an account:", err.Error())
		return nil
	}

	acc = &Account{name, passwordHash, char.Id, time.Unix(0, 0)}

	row := tx.QueryRow("INSERT INTO account (loginname, passwordhash, character) VALUES ($1, $2, $3) RETURNING created",
		name, passwordHash, acc.Character)
	err = row.Scan(&acc.Created)
	if err != nil {
		log.Println("Couldn't create new account:", err.Error())
		tx.Rollback()
		return nil
	}

	err = tx.Commit()
	if err != nil {
		log.Println("Couldn't commit transaction to create new account:", err.Error())
		tx.Rollback()
		return nil
	}

	return
}
示例#5
0
文件: service.go 项目: inve1/idyns
// Only admins can create users, for now
func UserPost(w http.ResponseWriter, r *http.Request) {
	name := mux.Vars(r)["username"]
	isadmin := r.FormValue("isadmin")
	password := r.FormValue("password")
	auth, _ := NewBasicFromRequest(r)
	fmt.Printf("isadmin %v ps %v", isadmin, password)
	if checkAdm(auth) {
		client := connectToRedis()
		defer client.Close()
		if client.Exists("user:"******"", 409)
		} else {
			hash, _ := bcrypt.Hash(password)
			client.HMSet("user:"******"isadmin", "1", "password", hash)
			fmt.Fprintf(w, "")
		}
	} else {
		http.Error(w, "", 403)
	}

}
示例#6
0
func (self *defaultAuther) Hash(password string, salt string) string {

	hash, _ := bcrypt.Hash(password, salt)

	return hash
}
示例#7
0
文件: user.go 项目: jh-bate/fantail
func (u *User) Encrypt() {
	u.Hash, _ = bcrypt.Hash(u.Hash)
}
示例#8
0
func Encrypt(p string) string {
	hash, _ := bcrypt.Hash(p)
	return hash
}