💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Gemigit › files › f12531322e8ecaf98c78e32f5e… captured on 2023-01-29 at 15:57:57. Gemini links have been rewritten to link to archived content

View Raw

More Information

➡️ Next capture (2023-03-20)

-=-=-=-=-=-=-

0 package auth

1

2 import (

3 "errors"

4 "gemigit/config"

5 "gemigit/db"

6 "gemigit/access"

7 "time"

8 )

9

10 var userAttempts = make(map[string]int)

11 var clientAttempts = make(map[string]int)

12

13 func Decrease() {

14 for {

15 userAttempts = make(map[string]int)

16 clientAttempts = make(map[string]int)

17 time.Sleep(time.Duration(config.Cfg.Protection.Reset) *

18 time.Second)

19 }

20 }

21

22 // Check if credential are valid then add client signature

23 // as a connected user

24 func Connect(username string, password string,

25 signature string, ip string) error {

26 attempts, b := userAttempts[username]

27 if b {

28 if attempts < config.Cfg.Protection.Account {

29 userAttempts[username]++

30 } else {

31 return errors.New("the account is locked, " +

32 "too many connections attempts")

33 }

34 } else {

35 userAttempts[username] = 1

36 }

37 attempts, b = clientAttempts[ip]

38 if b {

39 if attempts < config.Cfg.Protection.Ip {

40 clientAttempts[ip]++

41 } else {

42 return errors.New("too many connections attempts")

43 }

44 } else {

45 clientAttempts[ip] = 1

46 }

47 err := access.Login(username, password)

48 if err != nil {

49 return err

50 }

51

52 user, err := db.FetchUser(username, signature)

53 if err == nil {

54 db.SetUser(signature, user)

55 return nil

56 }

57 if !config.Cfg.Ldap.Enabled {

58 return err

59 }

60 err = db.Register(username, "")

61 if err != nil {

62 return err

63 }

64 user, err = db.FetchUser(username, signature)

65 if err != nil {

66 return err

67 }

68 db.SetUser(signature, user)

69 return nil

70 }

71