Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4973 right-hear 1
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
2
#include 
3
#include 
4
#include 
5
 
6
int
7
getlongpass(const char *prompt, char *password, int max_length)
8
{
9
  char *p = password;
10
  int c, count = 0;
11
 
12
  fflush(stdout);
13
  /* If we can't prompt, abort */
14
  if (fputs(prompt, stderr) < 0)
15
  {
16
    *p = '\0';
17
    return -1;
18
  }
19
 
20
  while (1)
21
  {
22
    /* Get a character with no echo */
23
    c = getkey();
24
 
25
    /* Exit on interrupt (^c or ^break) */
26
    if (c == '\003' || c == 0x100)
27
      exit(1);
28
 
29
    /* Terminate on end of line or file (^j, ^m, ^d, ^z) */
30
    if (c == '\r' || c == '\n' || c == '\004' || c == '\032')
31
      break;
32
 
33
    /* Back up on backspace */
34
    if (c == '\b')
35
    {
36
      if (count)
37
	count--;
38
      else if (p > password)
39
	  p--;
40
      continue;
41
    }
42
 
43
    /* Ignore DOS extended characters */
44
    if ((c & 0xff) != c)
45
      continue;
46
 
47
    /* Add to password if it isn't full */
48
    if (p < password + max_length - 1)
49
      *p++ = c;
50
    else
51
      count++;
52
  }
53
  *p = '\0';
54
 
55
  fputc('\n', stderr);
56
 
57
  return 0;
58
}