Example #1
0
func (self *AuthServer) LA_CheckAccount(req *protobuf.LA_CheckAccount, ret *protobuf.AL_CheckAccountResult) error {

	uid := common.GenUUID(req.GetAccount())

	if len(req.GetUid()) > 0 {
		if req.GetUid() != uid { //客户端伪造uid
			(*ret).SetResult(protobuf.AL_CheckAccountResult_AUTH_FAILED)
			return nil
		}
	}

	account := &protobuf.AccountInfo{}
	result, err := db.Query("AccountInfo", uid, account)

	if err != nil {
		(*ret).SetResult(protobuf.AL_CheckAccountResult_SERVERERROR)
		return nil
	}

	if result == false { //用户注册

		account.SetUid(uid)
		account.SetAccount(req.GetAccount())
		account.SetPassword(common.GenPassword(req.GetAccount(), req.GetPassword()))
		account.SetLanguage(req.GetLanguage())
		account.SetOption(req.GetOption())
		account.SetSessionKey(common.GenSessionKey())
		account.SetUdid(req.GetUdid())
		account.SetCreateTime(uint32(time.Now().Unix()))

		db.Write("AccountInfo", uid, account)
		logger.Info("Auth AccountInfo create")

	} else { //用户登陆
		if !common.CheckPassword(account.GetPassword(), req.GetAccount(), req.GetPassword()) {
			(*ret).SetResult(protobuf.AL_CheckAccountResult_AUTH_FAILED)
			return nil
		}
		account.SetSessionKey(common.GenSessionKey()) //保存进缓存
		db.Write("AccountInfo", uid, account)
		logger.Info("Auth Account find")
	}

	self.maincache.Do("SET", "SessionKey_"+uid, []byte(account.GetSessionKey()))

	(*ret).SetResult(protobuf.AL_CheckAccountResult_OK)
	(*ret).SetSessionKey(account.GetSessionKey())
	(*ret).SetUid(account.GetUid())

	logger.Info("ComeInto AuthServer.Login %v, %v", req, ret)

	return nil
}
Example #2
0
func testCommon() {
	logger.Info("uuid: %v", common.GenUUID("123"))
	logger.Info("uuid: %v", common.GenUUID("account"))

	passwdhash := common.GenPassword("account", "passwd")
	logger.Info("passwdhash: %v", passwdhash)
	logger.Info("check: %v", common.CheckPassword(passwdhash, "account", "passwd"))

	sessionKey := common.GenSessionKey()
	logger.Info("session: %v", sessionKey)
	logger.Info("check: %v", common.CheckSessionKey(sessionKey))
}