10 examples of 'golang login' in Go

Every line of 'golang login' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
140func (s *TsuruBoostraper) login(login, password string) error {
141 fmt.Fprintf(os.Stdout, "log in with default user: %s ", login)
142 logincmd := s.manager.Commands["login"]
143 s.context.Args = []string{login}
144 s.context.Stdin = strings.NewReader(fmt.Sprintf("%s\n", password))
145 err := logincmd.Run(&s.context, s.client)
146 if err != nil {
147 return fmt.Errorf("failed to login to tsuru: %s", err)
148 }
149 return nil
150}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

28func (j *JnprIOProc) Login(t *netconf.TransportTelnet, username string, password string) error {
29 t.WaitForString("ogin:")
30 t.Writeln([]byte(username))
31
32 t.WaitForString("assword:")
33 t.Writeln([]byte(password))
34
35 _, prompt, err := t.WaitForRegexp(promptRE)
36 if err != nil {
37 return err
38 }
39
40 switch string(prompt[0]) {
41 case ">":
42 j.cliMode = CLIModeCLI
43 case "%":
44 j.cliMode = CLIModeShell
45 default:
46 return fmt.Errorf("Cannot determine prompt '%s'", prompt[0])
47 }
48 return nil
49}
102func (s *Sina) Login(name string, pass string) interface{} {
103 url := "https://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.15)&_=1403138799543"
104 userInfo := make(map[string]string)
105 userInfo["UserName"] = bootstrap.Encode(base64.StdEncoding, name)
106 userInfo["PassWord"] = pass
107 cookie := s.getCookies(url, userInfo)
108 return cookie
109}
53func (auth *Authenticator) Login(username, password string) (User, error) {
54 lcun := strings.ToLower(username)
55
56 // user does not exist
57 user, exist := auth.Users[lcun]
58 if !exist {
59 return user, errors.New("user does not exist")
60 }
61
62 // bad password
63 if err := bcrypt.CompareHashAndPassword(user.Password, []byte(password)); err != nil {
64 return user, errors.New("bad password")
65 }
66
67 return user, nil
68}
45func (robot *Robot) Login() bool {
46 var addr = *host
47 fmt.Println("login...", addr)
48
49 //var addr = "http://47.52.241.13:9900"
50 response, err := http.Get(fmt.Sprintf("%s/login?a=%s&p=1111", addr, robot.account))
51 if err != nil {
52 log.Fatalln("login http.get fail:", err)
53 return false
54 }
55 defer response.Body.Close()
56 body, _ := ioutil.ReadAll(response.Body)
57 result := gameproto.UserLoginResult{}
58
59 umErr := gp.Unmarshal(body, &result)
60 if umErr != nil {
61 fmt.Println("err:", umErr, " result:", result)
62 return false
63 }
64 fmt.Println("login ok,", result.GateWsAddr)
65 robot.uid = uint64(result.Uid)
66 robot.key = result.Key
67 if *nettype == "ws" {
68 robot.gateAddr = "ws://" + result.GateWsAddr
69 } else {
70 robot.gateAddr = result.GateTcpAddr
71 }
72 return result.GetResult() == int32(gameproto.OK)
73}
163func (user *User)login(c *gin.Context) {
164 sess := sessions.Default(c)
165 sess.Set("public", user.ID.Hex())
166 sess.Save()
167}
75func Login(username, password string) bool {
76 for _, u := range UserList {
77 if u.Username == username && u.Password == password {
78 return true
79 }
80 }
81 return false
82}
32func (b *Bootstrap) login(username, password string) error {
33 var resp *gomatrix.RespLogin
34 var err error
35
36 fmt.Printf(
37 "\nmatrix bootstrap %+v login:\n username: %+v\n password: %+v\n",
38 b.HomeserverURL.Hostname(),
39 username,
40 password,
41 )
42 resp, err = b.Login(&gomatrix.ReqLogin{
43 Type: "m.login.password",
44 User: username,
45 Password: password,
46 })
47 if err != nil {
48 fmt.Printf(" err: %+v\n", err.Error())
49 return err
50 }
51 b.SetCredentials(resp.UserID, resp.AccessToken)
52 return nil
53}
31func (ue *UserEntity) Login() error {
32 user := ue.store.User()
33
34 if user == nil {
35 return errors.New("user was not initialized")
36 }
37
38 _, resp := ue.client.Login(user.Email, user.Password)
39
40 if resp.Error != nil {
41 return resp.Error
42 }
43
44 return nil
45}
12func login(cmd *cli.Cmd) {
13
14 email := cmd.String(cli.StringOpt{
15 Name: "email",
16 Desc: "User email",
17 EnvVar: "BZK_USER_EMAIL"})
18 password := cmd.String(cli.StringOpt{
19 Name: "password",
20 Desc: "User password",
21 EnvVar: "BZK_USER_PASSWORD"})
22
23 cmd.Action = func() {
24 if len(*email) == 0 {
25 *email = interactiveInput("Email", "")
26 }
27
28 if len(*password) == 0 {
29 fmt.Printf("Password: ")
30 bs, err:=gopass.GetPasswd()
31 if err != nil {
32 log.Fatal(err)
33 }
34 *password = string(bs)
35 }
36
37 _, err := NewClient()
38 if err != nil {
39 log.Fatal(err)
40 }
41
42 // TODO check credential. Create a /auth ressource ?
43 config, err := loadConfig()
44 if err != nil {
45 log.Fatal(fmt.Errorf("Unable to load Bazooka config, reason is: %v\n", err))
46 }
47
48 config.Username = *email
49 config.Password = *password
50
51 err = saveConfig(config)
52 if err != nil {
53 log.Fatal(fmt.Errorf("Unable to save Bazooka config, reason is: %v\n", err))
54 }
55 }
56
57}

Related snippets